【发布时间】:2011-10-04 09:24:35
【问题描述】:
我正在开发一个 Adobe AIR 应用程序,它可以将文件上传到运行 Apache 和 PHP 的 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;
}
【问题讨论】:
-
我知道 AIR 应用程序可以发送的 HTTP 请求数量没有功能限制。您可以发布用于发送请求的代码吗?您是否有机会修改 HTTPService 对象的“并发”属性?
-
@JasonDean - 我更新了帖子并添加了一些代码。我不会在任何地方修改并发属性。我尝试增加 requestTimeout 但这仅意味着如果文件非常大,上传可能需要很长时间才能超时失败。谢谢。
标签: http file-upload air wamp two-connection-limit