這應該是微不足道的,我很確定我之前做過一次。下載發佈到服務器的數據作爲來自Flex的文件
我試圖將數據發佈到服務器,並讓它作爲文件下載反彈回來,提示本地瀏覽器文件下載框。我知道服務器部分工作得很好,因爲我可以從演示Web表單發佈,但是當我運行以下Flex 3代碼時,我甚至無法接受請求觸發。
var fileRef:FileReference = new FileReference();
private function saveXmlAsFile(event:MouseEvent):void
{
var fileRequest:URLRequest = new URLRequest();
fileRequest.method = URLRequestMethod.POST;
fileRequest.url = "http://foo.com/dataBounce";
var urlVariables:URLVariables = new URLVariables();
urlVariables.content = "Test content to return" ;
// fileRequest.contentType = "application/x-www-form-urlencoded ";
urlVariables.fileName = "test.xml";
fileRef.addEventListener(SecurityEvent.ALL, onSecurityError);
fileRef.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError2);
fileRef.addEventListener(IOErrorEvent.NETWORK_ERROR, onNetworkError);
fileRef.addEventListener(Event.COMPLETE, onComplete);
try
{
fileRef.download(fileRequest, "test.xml");
}catch(error:Error) {
model.logger.error("unable to download file");
}
}
注意,當fileRef.download電話叫,我看不出有任何的要求是跨越使用傳統的螢火蟲或HttpWatch的瀏覽器工具,通過網絡進行。
編輯:我應該補充說這是用於Flash Player 10的<,所以我不能使用新的直接另存爲文件功能。
有什麼建議嗎?謝謝。
雖然我實際上並沒有上傳任何文件。只需發佈來自TextInput的數據。 – taudep 2010-07-08 16:54:45
下面是一個Adobe文檔的鏈接,看起來我應該可以做我想做的事,不需要調用fileRef.upload,因爲我實際上並沒有上傳文件:http://livedocs.adobe.com/flex /3/html/help.html?content=17_Networking_and_communications_7.html(請參閱從服務器下載文件部分) – taudep 2010-07-08 16:56:59
然後您需要使用URLRequest來保存文件的名稱。此外,URLRequest將是唯一下載的參數,因爲您不更改名稱。 HTH – adamcodes 2010-07-08 17:11:43