|
Page 1 of 1 |
|
Posted: Tue, 15th Jul 2014 10:36 Post subject: AJAX XHR2 upload with authentication |
|
 |
Previously when uploading a file, I just submitted a form and upon submission I would instantly receive my browsers authentication notice (against Apache, basic auth).
Now I switched to AJAX based uploads with progress and performance display, also without the page refresh at the end of the file upload. Sadly though, the full file gets uploaded, THEN you get the auth notification and then it uploads the file again.
Any idea how I could trigger the auth before? Should I create a dummy connection that would trigger auth before? Is that the official way to circumvent this?
democode:
Code: | function upload(thefile){
var m;
if ((m = prompt("Enter a comment"))!==null) {
...
$.ajax({
xhr: function() {
var xhr = new window.XMLHttpRequest();
xhr.upload.addEventListener("progress", function(evt){
if (evt.lengthComputable) {
var percentComplete = (evt.loaded / evt.total)*100;
counter = evt.loaded / 1048576;
$progress.text((speed!=0?" (" + speed.toFixed(2) + " MB/s)":""));
$pie.css(pieprogress(percentComplete, 24)).attr('title',percentComplete.toFixed(1) + "%");
}
}, false);
return xhr;
},
type: "POST",
url: document.forms["addFileForm"].action,
data: new FormData(document.forms["addFileForm"]),
processData: false,
contentType: false,
success: function () {
raiseAlert("success", "File uploaded successfully.", 2500);
angular.element(document.getElementById('svnlist')).scope().refresh();
}, complete: function () {
$busy.fadeOut(300);
clearInterval(progress);
}
});
}
};
|
|
|
Back to top |
|
 |
Werelds
Special Little Man
Posts: 15098
Location: 0100111001001100
|
|
Back to top |
|
 |
|
Posted: Tue, 15th Jul 2014 12:40 Post subject: |
|
 |
Anonymous access is a must in our tool and only for specific tasks auth is required.
Thanks for the suggestion, I think that option two is what I will use 
|
|
Back to top |
|
 |
|
Posted: Mon, 6th Oct 2014 19:16 Post subject: |
|
 |
I was able to circumvent the problem by simply sending a dummy post message which triggers server side authentication mechanism in the client browser Depending on the returned value the authentication is then accepted and the file actually uploaded.
|
|
Back to top |
|
 |
Page 1 of 1 |
All times are GMT + 1 Hour |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB 2.0.8 © 2001, 2002 phpBB Group
|
|
 |
|