How to change url dropzone? URL dynamically with ajax success

前端 未结 5 1443
青春惊慌失措
青春惊慌失措 2021-01-04 12:35

I read this: https://github.com/enyo/dropzone/wiki/Set-URL-dynamically but i dont got success... :( I have 1 form...

And i send the inputs with ajax.

The aj

5条回答
  •  一生所求
    2021-01-04 13:09

    New answer for an old question only because I found this answer and the link to the dropzone wiki and didn't like it. Modifying the options of the plugin multiple times like that seems very wrong.

    When dropzone uses some options it runs it through a resolveOption function passing in a files array. In the current branch you can define a function for the options: method, url and timeout.

    Here's a complete working example including delaying for the ajax:

    Dropzone.autoDiscover = false;
    
    const doStuffAsync = (file, done) => {
      fetch('https://httpbin.org/get').then((response) => {
        file.dynamicUploadUrl = `https://This-URL-will-be-different-for-every-file${Math.random()}`
        done();//call the dropzone done
      })  
    }
    
    const getMeSomeUrl = (files) => {
      return `${files[0].dynamicUploadUrl}?sugar&spice`;
    }
    
    let myDropzone = new Dropzone("#my-awesome-dropzone", {
      method: "put",
      accept: doStuffAsync,
      url: getMeSomeUrl
    });
    
    
    
    

提交回复
热议问题