[dancer-users] Code behaves differently on digitalocean.
Richard Reina
gatorreina at gmail.com
Sun Jan 10 13:39:15 GMT 2016
2016-01-10 1:48 GMT-06:00 Stefan Hornburg (Racke) <racke at linuxia.de>:
> On 01/10/2016 03:35 AM, Richard Reina wrote:
> > This code works (the file uploads) when I run it from my web app on my
> local host. However, it does not when I try it on the digitalocean version
> of my app. I get no errors and $file->copy_to($destination) returns true.
> But the file does not upload. Anyone have an idea as to what the problem
> could be?
> >
> > post '/upload' => sub {
> >
> > my $user_id = session 'UID';
> > my $d_filename = 'user_' . $user_id . '.jpg';
> >
> > my $file = request->upload('file');
> > my $tmpname = $file->tempname;
> > my $destination = $upload_dir . '/' . $d_filename;
> > my ($crslt) = $file->copy_to($destination) || warn $!;
> > unlink $tmpname if -e $tmpname;
> >
> > debug "crslt: ", $crslt;
> >
> > template 'upload';
> >
> > redirect '/playerdash';
> > };
> >
>
> Where did you define $upload_dir and what is the value of it?
>
> Regards
> Racke
>
>
Racke and Gabor, Thank you very much for the replies.
$upload_dir was being set just before the get route -- which I realize is
not correct so I have now put it in the post route like below and the
results are the same.
Both machines run perl (v5.20.2).
On the development machine I start Dancer2 with: plackup -r bin/app.psgi
On the production machine: service starman start; which uses argument:
'/home/starman/Almslete/bin/app.psgi (see starman.pl below) Gabor I
followed your excellent tutorial: http://perlmaven.com/getting-started-with-
perl-dancer-on-digital-ocean
post '/upload' => sub {
my $upload_route = '/upload';
my $upload_dir = 'public/profile_pics';
my $user_id = session 'UID';
my $d_filename = 'user_' . $user_id . '.jpg';
my $file = request->upload('file');
my $tmpname = $file->tempname;
debug "File Size: ", $file->size;
debug "file: ", $file->filename;
debug "tmpname: ", $file->tempname,
my $destination = $upload_dir . '/' . $d_filename;
debug "Destination: $destination\n";
my ($crslt) = $file->copy_to($destination) || warn $!;
#unlink $tmpname if -e $tmpname;
debug "crslt: ", $crslt;
template 'upload';
redirect '/playerdash';
};
/home/starman/starman.pl
#!/usr/bin/perl
use warnings;
use strict;
use Daemon::Control;
use Cwd qw(abs_path);
Daemon::Control->new(
{
name => "Starman",
lsb_start => '$syslog $remote_fs',
lsb_stop => '$syslog',
lsb_sdesc => 'Starman Short',
lsb_desc => 'Starman controls the web sites.',
path => abs_path($0),
#program => 'plackup -E deployment -s Starman',
program => '/usr/local/bin/starman',
program_args => [ '--workers', '3',
'/home/starman/Almslete/bin/app.psgi' ],
#plackup -E deployment -s Starman --workers=10 -p 5001 -a
bin/app.psgipl
user => 'starman',
group => 'starman',
pid_file => '/tmp/starman.pid',
stderr_file => '/tmp/starman.err',
stdout_file => '/tmp/starman.out',
fork => 2,
}
)->run;
Thanks again for the help.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20160110/7d9a104b/attachment.html>
More information about the dancer-users
mailing list