Code behaves differently on digitalocean.
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'; };
No idea here, just a few point to try to track down the issue: Do you use the same version of Perl? The same version of Dancer? Do you launch the app the same way on both places or do you, for example, use plackup on your development machine and Starman on the server? Try to eliminate any difference between the two setups and see if at some point it starts working on the server. (Or stops working on the development machine as well :) Gabor On Sun, Jan 10, 2016 at 3:35 AM, Richard Reina <gatorreina@gmail.com> 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'; };
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 -- Perl and Dancer Development Visit our Perl::Dancer conference 2015. More information on https://www.perl.dance.
2016-01-10 1:48 GMT-06:00 Stefan Hornburg (Racke) <racke@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.
On Sun, 2016-01-10 at 07:39 -0600, Richard Reina wrote:
$upload_dir was being set just before the get route -- which I realize is not correct
As an aside, it's probably best practice to define in your config file, rather than hard-coding into your code. That won't be a cause of your problem though.
post '/upload' => sub {
my $upload_route = '/upload'; my $upload_dir = 'public/profile_pics';
Have you tried using an absolute path? Or even tried something with open permissions like "/tmp"?
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 $!;
Do you get any warnings here? TBH, I don't even know if the precedence of the operators there will work correctly. I would always use "or" instead of "||" in a situation like that. It would also be worth doing a "warn 'test'" to check that your warnings are being logged somewhere that you can see them. Andy
2016-01-10 9:55 GMT-06:00 Andrew Beverley <andy@andybev.com>:
On Sun, 2016-01-10 at 07:39 -0600, Richard Reina wrote:
$upload_dir was being set just before the get route -- which I realize is not correct
As an aside, it's probably best practice to define in your config file, rather than hard-coding into your code. That won't be a cause of your problem though.
post '/upload' => sub {
my $upload_route = '/upload'; my $upload_dir = 'public/profile_pics';
Have you tried using an absolute path? Or even tried something with open permissions like "/tmp"?
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 $!;
Do you get any warnings here? TBH, I don't even know if the precedence of the operators there will work correctly. I would always use "or" instead of "||" in a situation like that.
It would also be worth doing a "warn 'test'" to check that your warnings are being logged somewhere that you can see them.
Andy
Andy, Thanks for the ideas. Absolute paths worked. Thanks again everybody for the helpful replies.
participants (4)
-
Andrew Beverley -
Gabor Szabo -
Richard Reina -
Stefan Hornburg (Racke)