jQuery File Upload with HttpHandler - Run web service call first?
I'm trying to use jQuery-File-Upload to upload one file to my server using
an ASP.net HttpHandler on the server-side. The upload works, but now I
need to run a web service call BEFORE I upload, then pass the data
returned from the web service call along with the upload so the file is
named according to the returned data. Here's the basic requirements:
Upload must be triggered by Javascript function (rather than the "add" event)
Run web service call first, send returned data to upload function
Restrict upload to one file
I'm not quite sure if this can be done, or how to do it. I believe I will
need to make use of the callbacks built into jQuery-File-Upload, but I've
been working on it for a couple days and haven't been able to get it to
work. Any tips or guidance as to how to get this accomplished?
Here's my exiting code, which I don't think is even close:
$('#upload').fileupload({
url: 'Handler/Upload.ashx',
xhrFields: { withCredentials: true },
dataType: 'json',
autoUpload: false,
maxNumberOfFiles: 1,
acceptFileTypes: /(\.|\/)(pdf|gif|jpe?g|png)$/i,
maxFileSize: 5000000, // 5 MB
formData: { "ActivityId": $.cookie("ActivityId") },
add: function (e, data) {
$("#icon").show().css('cursor', 'pointer')
.on('click', function () {
$("#filename").text("");
$(this).hide();
});
data.context = $("#btnSubmitForm").click(function () {
data.submit(); });
},
}).bind('fileuploadsubmit', function (e, data) {
var ActivityId = $.cookie("ActivityId");
if (ActivityId) {
data.formData = {"ActivityId" : ActivityId};
return true;
}
});
No comments:
Post a Comment