简体   繁体   English

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

[英]plupload - send another request parameter with uploaded file

plupload creates nice ids in file object . plupload文件对象中创建漂亮的ID。 How this id can be sent to the upload script? 如何将此ID发送到上传脚本? The upload script has 3 variables in $_POST - file name, chunk number and total number of chunks. 上传脚本在$_POST有3个变量 - 文件名,块号和块总数。

How to add another parameter to plupload's POST request (in my case, the file.id)? 如何在plupload的POST请求中添加另一个参数(在我的例子中,是file.id)?

The first step would be to add a handler to the BeforeUpload event. 第一步是向BeforeUpload事件添加处理程序。

Then, if you are using multipart, you can change the uploader settings to dynamically set different multipart params: 然后,如果您使用的是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). 如果你不使用multipart,你唯一的选择是将参数作为标题传递,或者手动将param添加到每个文件的URL(这两个选项也应该在BeforeUpload中完成)。 Note that when not using multipart, plupload will add the name and chunk params to the URL after any URL you already set for the uploader, for each file, so this is where extra params go. 请注意,当不使用multipart时,plupload会在您为上传器设置的任何URL 之后为每个文件添加namechunk参数到URL,因此这是额外的参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM