私は、Apache と PHP を実行している Web サーバーにファイルをアップロードできる Adobe AIR アプリケーションに取り組んでいます。複数のファイルを同時にアップロードすることができ、アプリケーションはさまざまな API 要求に対して Web サーバーも呼び出します。
私が抱えている問題は、2 つのファイルのアップロードを開始すると、進行中に他の HTTP 要求がタイムアウトになり、アプリケーションとユーザーの観点から問題が発生することです。
Adobe AIR アプリケーションは 2 つの HTTP 接続に制限されていますか、それとも何か他の問題が考えられますか? この問題について検索してもあまり見つかりませんでしたが、1 つの記事で、2 つの接続だけに限定されていないことが示されました。
ファイルのアップロードは 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;
}