I have an Angular application where I am using the drag-and-drop file upload component, Dropzone.js. The uploaded file will be posted directly to an Azure blob. Azure requires me to generate a unique URL for each file upload.
Dropzone.js has a config option called "url" that can be a string or a function. I need to call my angular service from this function to generate the Azure signed URL where the file will be sent. In my controller, I generate the config for Dropzone as:
var options = {
url: function (files) {
var f = files[0];
return _fileHandlingService.getUploadUrl(f.name);
},
maxFiles: 10,
maxFilesize: 20,
acceptedFiles: "image/*",
method: "PUT"
};
My file handling service is as follows:
getUploadUrl = function (filename) {
this.$http.get("/api/getUploadUrl", { params: { filename: filename } }).then(function (resp) {
return resp.data;
});
};
The problem is that the promise doesn't resolve in time for it to be provided to Dropzone and Dropzone doesn't support promises. How should this be handled assuming we don't rewrite Dropzone to support promises? I have been able to find a way to make everyting stop until the promise is resolved.
urlproperty which I'm guessing DropZone won't wait for. You should just wrap the entire options creation and whatever other calls you need to make in the promise resolution callback, ie_fileHandlingService.getUploadUrl(f.name).then(function(url) { var options = ....getAcceptedFiles()to grab all the files. Next run your service to get urls and store them in an array. Finally, call.processQueue(). The optionurlfunction processes your file array -- That won't get called (I think) until you actually start processing the queue. Unfortunately, with this method you'll have to press a button to start actual uploading..processQueue()so it will be "automatic" to the user.