Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
471 views
in Technique[技术] by (71.8m points)

javascript - plupload - send another request parameter with uploaded file

plupload creates 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.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The first step would be to add a handler to the BeforeUpload event.

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

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)

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 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...