0

I'm using FineUploader 5.11.9 "Traditional" to upload pictures to my web server, where a script written using the Perl CGI::Simple module is on the receiving end. Everything works fine on my internal development system - I use CGI::Simple::upload() to get the name of the file and then CGI::Simple::upload($file,$target) to magically copy the temp file to where I want it without having to mess around with filehandles (so much easier than with old CGI.pm, once you realise that you need to use CGI::Simple(-upload) because upload support is disabled by default!)

But I digress. Everything is fine on my development system, but on my production system only the first upload works, and then only if I do it soon after loading the webapp page. All subsequent uploads hang, and when I use the Web Inspector in Safari I see the calls to my CGI script have received a 401 Not Authorized response.

The production server is set with Basic Access Authentication (using AuthType Basic etc in a <Location "/"> section in the Apache httpd.conf file (actually default-ssl.conf which gets included by it), and Safari is set to remember the username/password, so I'm guessing that my first upload works because the authentication from when the web page loaded is still valid, but when I do another request it has gone stale.

I've had a look on the FineUploader documentation site and can't find anything about Authorization for its AJAX requests. Google found FineUploader - add authentication in header which might be the answer, but if it is, how do I find the right value to put in the "Authorization:Basic" header?

Community
  • 1
  • 1
kbro
  • 4,754
  • 7
  • 29
  • 40

1 Answers1

0

To change headers sent with a traditional upload request, use the setCustomHeaders API method:

uploader.setCustomHeaders(
   'Authorization', 'Basic ' + username + ':' + password, 
   fileId
)
Ray Nicholus
  • 19,538
  • 14
  • 59
  • 82
  • I think that should be `'Basic '+btoa(username+':'+password)`, but the real question is where do I get the username and password from? The entire website is protected using BAA so the user had to enter their username and password in a popup box from the browser before it could load the page containing my JavaScript. So how do I get the username and password from the browser? – kbro Nov 23 '16 at 23:49