默认情况下,flash无法
multipart使用参数创建请求,您必须手动构造它。这是我在项目中使用的简单实用程序方法:
private static const BOUNDARY:String = "boundary"; public static function createMultiPartRequest(url:String, bytes:ByteArray, fileProp:String="file1", fileName:String="file1.png", params:Object=null):URLRequest{ var request:URLRequest = new URLRequest(url); var header1:String = "rn--" + BOUNDARY + "rn" + "Content-Disposition: form-data; name=""+fileProp+""; filename=""+fileName+""rn" + "Content-Type: image/pngrn" + "rn"; var headerBytes1:ByteArray = new ByteArray(); headerBytes1.writeMultiByte(header1, "ascii"); var postdata:ByteArray = new ByteArray(); postData.writeBytes(headerBytes1, 0, headerBytes1.length); if(bytes) postData.writeBytes(bytes, 0, bytes.length); if (!params) params = {}; if (!params.Upload) params.Upload = "Submit Query"; for (var prop:String in params) { var header:String = "--" + BOUNDARY + "rn" + "Content-Disposition: form-data; name=""+prop+""rn" + "rn" + params[prop]+"rn" + "--" + BOUNDARY + "--"; var headerBytes:ByteArray = new ByteArray(); headerBytes.writeMultiByte(header, "ascii"); postData.writeBytes(headerBytes, 0, headerBytes.length); } request.data = postData; request.method = URLRequestMethod.POST; request.contentType = "multipart/form-data; boundary=" + BOUNDARY; return request;}
因此,您应该以以下方式修改代码:
var uploadRequest:URLRequest = createMultiPartRequest("http://127.0.0.1:8080/uploading/upservlet", myByteArray, "file1", recorder.output, {param1:value1}); var uploader:URLLoader = new URLLoader; uploader.addEventListener(ProgressEvent.PROGRESS, onUploadProgress); uploader.addEventListener(Event.COMPLETE, onUploadComplete); uploader.dataFormat = URLLoaderDataFormat.BINARY; uploader.load(uploadRequest);
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)