2012-02-13 70 views
0

我使用html上傳功能。使用給定的代碼它工作正常。在flex中使用URLRequest無法使用文件上傳

 <form id="avatar" enctype="multipart/form-data" 
      action="http://localhost:8080/alfresco/service/slingshot/profile/uploadavatar? 
        alf_ticket=TICKET_7475e180e8d258c0341fc745a3a35274d0a06e50" 
      method="post"> 

    <input type="text" name="username" value="ken"/> 

選擇一個文件:

<input type="file" name="filedata" /> 
    <input type="submit" name="button" value="upload"//form 

相同的功能我在柔性曾嘗試:

var uploadURL:URLRequest = new URLRequest();   
uploadURL.url="http://localhost:8080/alfresco/service/slingshot/profile/uploadavatar?alf_ticket=TICKET_7475e180e8d258c0341fc745a3a35274d0a06e50""; 
uploadURL.method=URLRequestMethod.POST; 
uploadURL.contentType="multipart/form-data"; 
var params:URLVariables = new URLVariables(); 
params.username ="admin"; 
params.filedata=fileRef.data; 
uploadURL.data = params; 
fileRef.upload(uploadURL) 

,但得到錯誤的請求錯誤。所以任何人都知道,我在代碼中犯了什麼錯誤。請與我分享。

+0

您是否檢查了您要發送給服務器的內容?嘗試安裝www.charlesproxy.com並檢查您的請求和響應對象中的內容。希望這可以幫助。 – Simsons 2012-02-13 11:37:37

回答

0

在POST請求中,您嘗試在URL..try中發送參數,將alf_ticket作爲params的屬性發送。

+0

我試着像你說的,但仍然不工作...感謝您的回覆 – user1206485 2012-02-15 07:04:16

+0

如果我嘗試使用基於flex的表單來上傳文件。那麼它工作正常。 – user1206485 2012-02-20 06:41:52