我正在开发一个 Adobe AIR 应用程序,它可以将文件上传到运行 Apache 和 PHP 的 Web 服务器。可以同时上传多个文件,并且应用程序还调用 Web 服务器以获取各种 API 请求。
我遇到的问题是,如果我开始两个文件上传,而它们正在进行中,任何其他 HTTP 请求都会超时,这会导致应用程序出现问题,并且从用户的角度来看。
Adobe AIR 应用程序是否仅限于 2 个 HTTP 连接,或者可能是其他问题?通过搜索这个问题,我没有发现太多,但一篇文章确实表明它不仅限于两个连接。
文件上传通过调用 File 类上传方法执行,API 调用使用 HTTPService 类完成。我正在使用的开发 Web 服务器是 WAMP 服务器,但是当应用程序发布时,它将与 LAMP 服务器通信。
谢谢,格兰特
这是我用来上传文件的代码:
protected function btnAddFile_clickHandler(event:MouseEvent):void
{
// Create a new File object and display the browse file dialog
var uploadFile:File = new File();
uploadFile.browseForOpen("Select File to Upload");
uploadFile.addEventListener(Event.SELECT, uploadFile_SelectedHandler);
}
private function uploadFile_SelectedHandler(event:Event):void
{
// Get the File object which was used to select the file
var uploadFile:File = event.target as File;
uploadFile.addEventListener(ProgressEvent.PROGRESS, file_progressHandler);
uploadFile.addEventListener(IOErrorEvent.IO_ERROR, file_ioErrorHandler);
uploadFile.addEventListener(Event.COMPLETE, file_completeHandler);
// Create the request URL based on the download URL
var requestURL:URLRequest = new URLRequest(AppEnvironment.instance.serverHostname + "upload.php");
requestURL.method = URLRequestMethod.POST;
// Set the post parameters
var params:URLVariables = new URLVariables();
params.name = "filename.ext";
requestURL.data = params;
// Start uploading the file to the server
uploadFile.upload(requestURL, "file");
}
以下是 API 调用的代码:
private function sendHTTPPost(apiFile:String, postParams:Object, resultCallback:Function, initialCallerResultCallback:Function):void
{
var httpService:mx.rpc.http.HTTPService = new mx.rpc.http.HTTPService();
httpService.url = AppEnvironment.instance.serverHostname + apiFile;
httpService.method = "POST";
httpService.requestTimeout = 10;
httpService.resultFormat = HTTPService.RESULT_FORMAT_TEXT;
httpService.addEventListener("result", resultCallback);
httpService.addEventListener("fault", httpFault);
var token:AsyncToken = httpService.send(postParams);
// Add the initial caller's result callback function to the token
token.initialCallerResultCallback = initialCallerResultCallback;
}