javascript plupload - 使用上传的文件发送另一个请求参数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9015944/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 05:20:07  来源:igfitidea点击:

plupload - send another request parameter with uploaded file

javascriptfile-uploaduploadplupload

提问by TMS

pluploadcreates nice ids in file object. How this id can be sent to the upload script? The upload script has 3 variables in $_POST- file name, chunk number and total number of chunks.

plupload文件对象中创建了很好的 id 。如何将此 id 发送到上传脚本?上传脚本中有 3 个变量$_POST- 文件名、块号和块总数。

How to add another parameter to plupload's POST request (in my case, the file.id)?

如何将另一个参数添加到 plupload 的 POST 请求(在我的例子中是 file.id)?

回答by gonchuki

The first step would be to add a handler to the BeforeUploadevent.

第一步是向BeforeUpload事件添加处理程序。

Then, if you are using multipart, you can change the uploader settings to dynamically set different multipart params:

然后,如果您使用 multipart,您可以更改上传器设置以动态设置不同的 multipart 参数:

plupload_instance.bind('BeforeUpload', function (up, file) {
    up.settings.multipart_params = {fileid: file.id}
});

(warning: this example overrides any and all multipart_params, you can play it smarter than that by just setting fileid)

(警告:这个例子覆盖了任何和所有的 multipart_params,你可以通过设置 fileid 来更聪明地播放它)

if you are not using multipart, your only options would be to pass the argument as a header, or to manually add the param to the URL for each file (these 2 options should also be done within BeforeUpload). Note that when not using multipart, plupload will add the nameand chunkparams to the URL afterany URL you already set for the uploader, for each file, so this is where extra params go.

如果您不使用 multipart,您唯一的选择是将参数作为标头传递,或者手动将参数添加到每个文件的 URL(这两个选项也应该在 BeforeUpload 中完成)。请注意,当不使用 multipart 时,plupload 会将namechunkparams添加到您已经为上传器设置的任何URL之后的URL 中,对于每个文件,因此这是额外参数的位置。