I'm need to simulate a web form's ability to include as many File inputs as one wishes in the FORM and have all the files arrive together in one request.
What's the prescribed method for performing said operation in AS3? (I'm using AIR, but I doubt that makes any differe开发者_JAVA技巧nce).
TIA
You can do a multipart form upload. I think the class I used is at http://blog.inspirit.ru/?p=139, but I would have to double check when I get to the office.
EDIT: Yes, the link above is correct. This particular class makes file uploads and multipart/form-data
pretty much a no brainer in AS3.
Like I said in the comment, I hate answering my own questions, but I found this solution: http://blog.mikestead.me/upload-multiple-files-with-a-single-request-in-flash/ and it works REALLY nicely and is entirely code complete, I had to do virtually no noodling at all. The only thing the docs fail to detail (which I'll add here) is that on the server side (specifically in PHP) the files arrive hash indexed by the variable name you set. So when you do
urlVariables["image1"] = new URLFileVariable(filePicker.data, filePicker.name); //this adds your file to the request in flash
Then on the PHP side you will find that file in
$_FILES["image1"]["tmp_name"];
You have two methods: zipping, or tracking multiple uploads.
If you want to zip the files, here is a walk-through on how to go about zipping, uploading, and unzipping from AIR.
If you want to upload multiple files, what you need to do is have an Array of booleans or a counter that keeps track of how many uploads were started. Then on an an event capturing upload completion, the booleans need to be turned from false
to true
or another counter needs to count the completions. Once all booleans are true or the two counters values match, you know all the files have been uploaded.
Here's some pseudo code:
fileCount= 0
fileUploadCompleteCount = 0
foreach(file in fileArray)
fileCount++
file.listenForUploadComplete(uploadComplete)
function uploadComplete()
fileUploadCompleteCount++
checkUploadProgress()
function checkUploadProgress()
if(fileUploadCompleteCount == fileCount)
// all files have been uploaded
精彩评论