首页 > 解决方案 > DropzoneJS - 创建自己的函数来上传文件

问题描述

我使用 DropzoneJS 库在我的网站上上传文件。现在,我想创建自己的函数来上传排队的文件。

我知道,我可以通过这种方式获取所有这些文件:

files = myDropzone.getQueuedFiles();

但是我现在如何创建一个 ajax 请求来发送这些文件呢?我需要类似file_get_contents()函数(如在 PHP 中)来获取这些文件的内容,然后使用该参数发送 ajax 帖子。

谢谢你的帮助。

标签: javascriptdropzone.js

解决方案


也许您可以提供更多背景信息。如果我理解正确:

function sendFile(file) {
   // Do ajax things here e.g. check out the link below
}


const files = myDropzone.getQueuedFiles(); // I'm assuming this returns an array?
files.forEach(sendFile) // For each loops over the array, and calls the sendFile function with as first parameter the current item in the array, which is in your case one of your files

使用 vanilla javascript 发出 AJAX 请求: https ://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest


推荐阅读