动态 url 通过 http 请求 - Dropzone.js
Dynamic url via http request - Dropzone.js
问题: 通过 dropzone.js
上传文件后出现此错误
POST http://localhost:8080/[object%20Promise] 404 (Not Found)
我正在使用 dropzone.js 库以便在应用程序上上传视频。
每个文件的 url 每次都是 不同的 。所以我发出 http 请求 - 使用 axios - 以便每次都获得 url.
我找到的唯一可能的解决方案是将回调函数传递给 url (Dropzone.options):
var myDropzone = new Dropzone(".my-upload-container", {
url: axios.post('/createURL)
.then( function (response) {
var theURL = bla
return theURL
})
});
当我上传文件并且 Dropzone 正在发送 POST 请求时,我收到此 404 错误。
问题:
我怎样才能得到我想要的正确 url?
我想要的 url 示例如下:http://blabla.com/v1/key=bla&token=bla
这是对同一问题的回答:
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
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.4.0/min/dropzone.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.4.0/min/dropzone.min.css">
<form action="/file-upload" class="dropzone" id="my-awesome-dropzone">
</form>
问题: 通过 dropzone.js
上传文件后出现此错误POST http://localhost:8080/[object%20Promise] 404 (Not Found)
我正在使用 dropzone.js 库以便在应用程序上上传视频。 每个文件的 url 每次都是 不同的 。所以我发出 http 请求 - 使用 axios - 以便每次都获得 url.
我找到的唯一可能的解决方案是将回调函数传递给 url (Dropzone.options):
var myDropzone = new Dropzone(".my-upload-container", {
url: axios.post('/createURL)
.then( function (response) {
var theURL = bla
return theURL
})
});
当我上传文件并且 Dropzone 正在发送 POST 请求时,我收到此 404 错误。
问题: 我怎样才能得到我想要的正确 url?
我想要的 url 示例如下:http://blabla.com/v1/key=bla&token=bla
这是对同一问题的回答:
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
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.4.0/min/dropzone.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.4.0/min/dropzone.min.css">
<form action="/file-upload" class="dropzone" id="my-awesome-dropzone">
</form>