2012-05-27 68 views
2

我有一個使用拖放在我的桌面Flex 4.6應用程序中的視圖創建的zip文件。使用HTTP POST通過動作上傳一個zip文件3.0

這會觸發一個將自動上傳zip文件的服務。

我能夠使用下面的代碼發送有關zip文件的元數據到服務器。

 var urlRequest:URLRequest = new URLRequest(PUBLISH_ZIP_FILE_URL); 
     // set to method=POST 
     urlRequest.method = URLRequestMethod.POST;   



     var params:URLVariables = new URLVariables(); 



     params['data[File][title]'] = 'Title1'; 
     params['data[File][description]'] = 'desc';   
     // params['data[File][filename]'] = I am not sure exactly what to use here 
     // If this is a webpage, I expect to use input type="file" with the name as data[File][filename] 


     urlRequest.data = params; 

     addLoaderListeners(); 

     // set it such that data format is in variables 
     loader.dataFormat = URLLoaderDataFormat.VARIABLES; 

     loader.load(urlRequest); 

我已閱讀https://stackoverflow.com/questions/8837619/using-http-post-to-upload-a-file-to-a-website

然而,他們立刻開始了與ByteArray的,這我不知道如何轉換我的zip文件的。

請指教。

回答

4

尷尬,但我發現我的答案42分鐘後,我發佈的問題。

有點橡膠鴨問題解決在這裏。

http://www.codinghorror.com/blog/2012/03/rubber-duck-problem-solving.html

簡短的回答:使用File類,特別是從該FileReference類擴展的方法upload

龍答:

 var urlRequest:URLRequest = new URLRequest(PUBLISH_ZIP_FILE_URL); 
     // set to method=POST 
     urlRequest.method = URLRequestMethod.POST; 

     var params:URLVariables = new URLVariables(); 

     params['data[File][title]'] = 'Title1'; 
     params['data[File][description]'] = 'desc'; 

     // this is where we include those non file params and data 
     urlRequest.data = params; 


     // now we upload the file 
     // this is how we set the form field expected for the file upload 
     file.upload(urlRequest, "data[File][filename]"); 
+0

感謝更新 – hooleyhoop

+0

如果這對你的工作,你應該能夠接受自己的答案,只是幫助清理名單未回答VS回答。 – shaunhusain

+0

@shaunhusain也許你不知道。但是在接受自己對自己問題的答案方面存在時間延遲。除非48小時之後,否則我不能接受。 –

相關問題