Nginx FCGIWrap Perl: File Upload not working.

Alexander Jaiboy alex50504u2 at yahoo.co.in
Mon Apr 1 09:34:06 UTC 2019


Hi All,

I am new to NGINX webserver. I am trying to up host my websites using NGINX webserver. The backend is Perl CGI scripts (i am using fcgiwrap for the handling the CGI requests).I am finding difficulty with file upload. The file is loaded to the temporary location specificied in the NGINX config but upload is not working. File is present in the final destination folder with the correct filename but the size of the file is zero.

Any help is much appreciated.
NGINX config ->
 location ~ /bin/diag/upload {
 # Store files to this directory  upload_store /alex/pil/upload 1; upload_store_access user:rw group:rw all:rw;

 # Pass altered request body to this location upload_pass @fastcgi; upload_pass_args on;
 # Set specified fields in request body upload_set_form_field $upload_field_name "$upload_file_name"; upload_set_form_field $upload_field_name.name "$upload_file_name";
 upload_set_form_field $upload_field_name.content_type "$upload_content_type"; upload_set_form_field $upload_field_name.path "$upload_tmp_path";  # Inform backend about hash and size of a file upload_aggregate_form_field $upload_field_name.size "$upload_file_size";
 #Pass all fields of the form upload_pass_form_field ".*"; 
 upload_cleanup 400 404 499 500-505; }
 location @fastcgi { fastcgi_index index; fastcgi_intercept_errors on;
 fastcgi_pass unix:/tmp/cgi.sock;
 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include /etc/nginx/fastcgi_params;  }
Upload Perl Script is ->

Parameters to the perl subroutine are1. HTML form name.2. destination folder to which the file should be uploaded.3. Name of the file when it is placed in the destination.
sub UploadFile{ binmode(STDIN);
 my $fh; my ( $form, $destfolder, $destname ) = @_; my ( $handle ); my ( $filename );
 system("logger -p user.debug -t diag.upload UploadFile: @_ "); system("logger -p user.debug -t diag.upload UploadFile: $form "); system("logger -p user.debug -t diag.upload UploadFile: $destfolder "); system("logger -p user.debug -t diag.upload UploadFile: $destname ");
 $handle = upload($form);
 $filename = $destfolder."/".$destname;
 unless ( open( $fh, '>', "$filename") ) { system("logger -p user.debug -t diag.upload UploadFile: Error while opening file '$filename' for write. Error: $!. [$0 -> $$]"); return; }
 binmode $fh;
 while (<$handle>) {
 print $fh $_; } close($handle); close($fh);}
Parameters passed to the Upload File Subroutine- >Apr  1 10:06:52 (none) user.debug diag.upload: UploadFile: datasheet /alex/pil/www/html/dataman datasheet.pdfApr  1 10:06:52 (none) user.debug diag.upload: UploadFile: datasheetApr  1 10:06:52 (none) user.debug diag.upload: UploadFile: /alex/pil/www/html/datamanApr  1 10:06:52 (none) user.debug diag.upload: UploadFile: datasheet.pdf
HTML form related data - >                       <form name="upload" method="post" action="/bin/diag/upload" enctype="multipart/form-data">                        <input type="hidden" name="uploadtype" value="2">                        <table border="0" width="90%">                          <tr>                            <td width="20%">Datasheet</td>                            <td width="40%"><input type="file" name="datasheet"><br></td>                            <td width="40%"> 
Error occurs during the upload  - >

File handle is not returned when upload() is called with the HTML form name.$handle = upload($form);

FastCGI sent in stderr: "Use of uninitialized value $handle in <HANDLE> at /alex/bin/diag/upload line 275. at /lxi/pil/www/bin/diag/upload line 275. main::UploadFile("datasheet", "/lxi/pil/www/html/dataman", "datasheet.pdf") called at /alex/bin/diag/upload line 137" while reading response header from upstream, client: 192.168.2.130, server: localhost, request: "POST /bin/diag/upload HTTP/1.1", upstream: "fastcgi://unix:/tmp/cgi.sock:", host: "192.168.2.145", referrer: "http://192.168.2.145/bin/diag/stage2"
Do i have to add anymore changes in the NGINX config so that the form data based file handler can be retrieved by the Perl CGI upload function?

Any help is much appreciated?
Thanks,
Alex.














-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20190401/601b06ab/attachment.html>


More information about the nginx mailing list