angularjs - Get Upload URL from Angular Service -


i have angular application using drag-and-drop file upload component, dropzone.js. uploaded file posted directly azure blob. azure requires me generate unique url each file upload.

dropzone.js has config option called "url" can string or function. need call angular service function generate azure signed url file sent. in controller, generate config 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 follows:

getuploadurl = function (filename) {             this.$http.get("/api/getuploadurl", { params: { filename: filename } }).then(function (resp) {                 return resp.data;             });         }; 

the problem promise doesn't resolve in time provided dropzone , dropzone doesn't support promises. how should handled assuming don't rewrite dropzone support promises? have been able find way make everyting stop until promise resolved.

dropzone has callback named "accept". 1 of parameters function gets called if successful. result, can call done function when our promise returns. 1 downside method urls generated when files queued vs uploaded. in case, there small chance url expire depending on expiration date , how long takes user upload. config options like:

var options = {                 url: function (files) {                     var f = files[0];                     return f.uploadurl;                 },                 maxfiles: 10,                 maxfilesize: 20,                 acceptedfiles: "image/*",                 method: "put",                 accept: function (file, done) {                     _filehandlingservice.getuploadurl(file.name).then(function (data) {                         file.uploadurl = data;                         done();                     });                 }             }; 

Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -