After generating an images for preview and thumbnail, using ImageSnapshot, I was need to upload them to a server. But when I was try to upload them one another, Flash Player Security start to demand user action on each download action, not only for first.
Was created a class to construct multipart/form-data request with more than 1 file data in it, and upload several files using 1 request and 1 user action.
Main target of this class is to upload mutiple data by one user
action.
Takes an array with prepared DTO as input;
Returns ByteArray to use as post data in UrlRequest as
output; ByteArray is formatter as multipart/form-data request,
as format is similar to FireFox request.
DTO can be generated via POSTUploadBuilder.buildUploadDataVO
method.
DTO structure: fileName : String; fileData : ByteArray; dataName : String;
Usage example:
var request : URLRequest = new URLRequest(
"http://somehost/upload );
request.contentType = 'multipart/form-data;
boundary=' + POSTUploadBuilder.boundary;
request.method = URLRequestMethod.POST;
var arr : Array = [];
for ( var i:uint = 0; i < fileList.length; ++i )
{
arr.push( POSTUploadBuilder.buildUploadDataVO(
fileList[i].name, fileList[i].data, fileList[i].name ) );
}
request.data = POSTUploadBuilder.buildPOSTData(
arr );
var loader : URLLoader = new URLLoader();
loader.addEventListener( Event.COMPLETE,
onUploadComplete );
loader.addEventListener( IOErrorEvent.IO_ERROR,
onUploadError );
loader.addEventListener(
SecurityErrorEvent.SECURITY_ERROR, onUploadError );
loader.dataFormat = URLLoaderDataFormat.BINARY;
loader.load( request );
+