Note that there are some explanatory texts on larger screens.

plurals
  1. PONo file being uploaded in Flex
    text
    copied!<p>I am trying to upload a single text file that is 1kb to the server. For whatever reason the data that I receive does not contain the file info. So FileItem.Write(file) does not work. Since FileItem says the size is 0.</p> <p>I don't think this is a connection issue because I managed to receive the URLVariables. The only thing that doesn't come through is the actual file.</p> <p>I followed the adobe flex guide, but it still doesn't work. (<a href="http://livedocs.adobe.com/flex/3/html/help.html?content=17_Networking_and_communications_7.html" rel="nofollow">http://livedocs.adobe.com/flex/3/html/help.html?content=17_Networking_and_communications_7.html</a>)</p> <p>No errors get thrown and a event complete gets triggered.</p> <p>Any suggestions?</p> <p>flex 3.2 sdk Jboss server java doPost</p> <p>EDIT: Added source code</p> <p>CertificateUploadServlet.java</p> <pre><code>import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.List; import java.util.ListIterator; import javax.servlet.ServletConfig; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.FileUploadException; import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.servlet.ServletFileUpload; public class CertificateUploadServlet extends HttpServlet { public void init(ServletConfig config) throws ServletException { super.init(config); } public void doPost(HttpServletRequest request, HttpServletResponse response) { File disk = null; FileItem item = null; DiskFileItemFactory factory = new DiskFileItemFactory(); ListIterator iterator = null; List items = null; Servlet FileUpload upload = new ServletFileUpload(factory); try { items = upload.parseRequest(request); }catch (FileUploadException e1) { // Oh Noes! } iterator = items.listIterator(); while(iterator.hasNext()) { item = (FileItem) iterator.next(); if(item.isFormField()) { }else { try { PrintWriter out1 = new PrintWriter(new BufferedWriter(new FileWriter("C:/Test/processUploadedFile2.txt",true))); out1.println("item.getContentType():\t\t "+item.getContentType()); out1.println("item.getName:\t\t "+ item.getName()); out1.println("item.getSize:\t\t" + item.getSize()); out1.println("item.getString:\t\t" + item.getString()); out1.println("item.getFieldName:\t\t"+item.getFieldName()); out1.println("item.isInMemory:\t\t" + item.isInMemory()); out1.println("item.toString():\t\t" + item.toString()); out1.close(); } catch(IOException e) { // oh Noes~ } } } } </code></pre> <p>}</p> <p>dataTest.mxml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="horizontal" creationComplete="init()"&gt; &lt;mx:Script&gt; &lt;![CDATA[ import flash.netFileReference; import mx.controls.Alert; private var fileRef:FileReference = new FileReference(); private function init():void { fileRef.addEventListener(Event.SELECT, selectHandler); fileRef.addEventListener(Event.COMPLETE, completeHandler); } private function selectHandler(event:Event):void { Alert.show("Selected..."); var request:URLRequest= new URLRequest("https://localhost/scm/uploadServlet"); fileRef.upload(request); } private function completeHandler(event:Event):void { Alert.show("File got uploaded"); } ]]&gt; &lt;/mx:Script&gt; &lt;mx:Button id="mBrowseButton" label="browse..." click="fileRef.browse()" /&gt; &lt;/mx:Application&gt; </code></pre> <p>item.getName: returns the correct file name that I want to upload</p> <p>but item.getSize always returns 0 and thus when I try to write the file on the server it is always empty.</p> <p>More info:</p> <p>I am able to add variables to URLVariables class and retrieve it in the java class. The only problem is that the file does not get transferred.</p> <p>Output:</p> <pre><code>Single file upload test ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ item.toString(): name=null, StoreLocation=C:\test\jboss-eap-5.1\jboss-as\server\test\work\jboss.web\localhost\scm\upload_76556a96_14064a51ded__7ffa_00000000.tmp, size=10bytes, isFormField=true, FieldName=Filename item name: Filename value: Cookie.txt item.toString(): name=Cookie.txt, StoreLocation=C:\test\jboss-eap-5.1\jboss-as\server\test\work\jboss.web\localhost\scm\upload_76556a96_14064a51ded__7ffa_00000001.tmp, size=0bytes, isFormField=false, FieldName=Filedata item.getName() : Cookie.txt item.getContentType(): application/octet-stream item.getSize: 0 item.getString: item.getFieldName: Filedata item.isInMemory: true item.toString(): name=Cookie.txt, StoreLocation=C:\test\jboss-eap-5.1\jboss-as\server\test\work\jboss.web\localhost\scm\upload_76556a96_14064a51ded__7ffa_00000001.tmp, size=0bytes, isFormField=false, FieldName=Filedata item name: Upload value: Submit Query Multifile upload test ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ item.toString(): name=null, StoreLocation=C:\test\jboss-eap-5.1\jboss-as\server\test\work\jboss.web\localhost\scm\upload_76556a96_14064a51ded__7ffa_00000003.tmp, size=10bytes, isFormField=true, FieldName=Filename item name: Filename value: Cookie.txt item.toString(): name=Cookie.txt, StoreLocation=C:\test\jboss-eap-5.1\jboss-as\server\test\work\jboss.web\localhost\scm\upload_76556a96_14064a51ded__7ffa_00000004.tmp, size=0bytes, isFormField=false, FieldName=Filedata ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ item.toString(): name=null, StoreLocation=C:\test\jboss-eap-5.1\jboss-as\server\test\work\jboss.web\localhost\scm\upload_76556a96_14064a51ded__7ffa_00000006.tmp, size=10bytes, isFormField=true, FieldName=Filename item name: Filename value: doPost.txt item.toString(): name=doPost.txt, StoreLocation=C:\test\jboss-eap-5.1\jboss-as\server\test\work\jboss.web\localhost\scm\upload_76556a96_14064a51ded__7ffa_00000007.tmp, size=0bytes, isFormField=false, FieldName=Filedata Single file upload test ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ item.toString(): name=Cookie.txt, StoreLocation=C:\test\jboss-eap-5.1\jboss-as\server\test\work\jboss.web\localhost\scm\upload_76556a96_14064a51ded__7ffa_00000010.tmp, size=0bytes, isFormField=false, FieldName=Filedata item name: Filename value: Cookie.txt item.getName() : Cookie.txt item.getContentType(): application/octet-stream item.getSize: 0 item.getString: item.getFieldName: Filedata item.isInMemory: true item.toString(): name=Cookie.txt, StoreLocation=C:\test\jboss-eap-5.1\jboss-as\server\test\work\jboss.web\localhost\scm\upload_76556a96_14064a51ded__7ffa_00000010.tmp, size=0bytes, isFormField=false, FieldName=Filedata item name: Upload value: Submit Query </code></pre> <p>Edit: More info. Following output came from user c.s code. I can't figure out why it still doesn't let me show the info when I do it the way it was documented.</p> <pre><code>accept:text/* content-type:multipart/form-data; boundary=----------ae0ae0ae0GI3ae0GI3ae0Ij5gL6cH2 user-agent:Shockwave Flash host:localhost content-length:1019 connection:Keep-Alive cache-control:no-cache cookie:JSESSIONID=BE2BF803041A7324CAF21445F6F3389C ------------ae0ae0ae0GI3ae0GI3ae0Ij5gL6cH2 Content-Disposition: form-data; name="Filename" Cookie.txt ------------ae0ae0ae0GI3ae0GI3ae0Ij5gL6cH2 Content-Disposition: form-data; name="Filedata"; filename="Cookie.txt" Content-Type: application/octet-stream en.wikipedia.org FALSE / FALSE 0 BCSI-CS-1b3dbb382aea0366 2 en.wikipedia.org FALSE / FALSE 1404323604 centralnotice_bannercount_fr12 1 en.wikipedia.org FALSE / FALSE 1374590485 centralnotice_bucket 0-4.2 en.wikipedia.org FALSE / FALSE 1373131359 mediaWiki.user.bucket%3Aext.articleFeedbackv5%4011-tracking 11%3Aignore en.wikipedia.org FALSE / FALSE 1373131359 mediaWiki.user.bucket%3Aext.articleFeedbackv5%405-links 5%3AX en.wikipedia.org FALSE / FALSE 1373131359 mediaWiki.user.bucket%3Aext.articleFeedbackv5%406-form 6%3A6 en.wikipedia.org FALSE / FALSE 0 uls-previous-languages %5B%22en%22%5D ------------ae0ae0ae0GI3ae0GI3ae0Ij5gL6cH2 Content-Disposition: form-data; name="Upload" Submit Query ------------ae0ae0ae0GI3ae0GI3ae0Ij5gL6cH2-- // dumpRequest = false output ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ item.getContentType(): null item.getName: null item.getSize: 10 item.getString: Cookie.txt item.getFieldName: Filename item.isFormField: true item.isInMemory: true item.toString(): name=null, StoreLocation=C:\test\jboss-eap-5.1\jboss-as\server\test\tmp\upload__272408b1_140738428eb__7ffa_00000006.tmp, size=10bytes, isFormField=true, FieldName=Filename ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ item.getContentType(): application/octet-stream item.getName: Cookie.txt item.getSize: 0 item.getString: item.getFieldName: Filedata item.isFormField: false item.isInMemory: true item.toString(): name=Cookie.txt, StoreLocation=C:\test\jboss-eap-5.1\jboss-as\server\test\tmp\upload__272408b1_140738428eb__7ffa_00000007.tmp, size=0bytes, isFormField=false, FieldName=Filedata ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ item.getContentType(): null item.getName: null item.getSize: 12 item.getString: Submit Query item.getFieldName: Upload item.isFormField: true item.isInMemory: true item.toString(): name=null, StoreLocation=C:\test\jboss-eap-5.1\jboss-as\server\test\tmp\upload__272408b1_140738428eb__7ffa_00000008.tmp, size=12bytes, isFormField=true, FieldName=Upload </code></pre> <p>More information:</p> <p>Version information</p> <pre><code>Apache Maven: 2.2.1 Java version: 1.6.0_39 fileupload: 1.2 Commons-IO: 1.4 Internet Explorer: 8.0.7601.17514 Flash Player: 11.8.800.94 </code></pre> <p>More output information. First attempt is using cookie.txt while the second is test.txt</p> <pre><code>#########################True/True ------------GI3gL6Ef1GI3cH2KM7ei4cH2gL6ei4 Content-Disposition: form-data; name="Filename" Cookie.txt ------------GI3gL6Ef1GI3cH2KM7ei4cH2gL6ei4 Content-Disposition: form-data; name="Filedata"; filename="Cookie.txt" Content-Type: application/octet-stream en.wikipedia.org FALSE / FALSE 0 BCSI-CS-1b3dbb382aea0366 2 en.wikipedia.org FALSE / FALSE 1404323604 centralnotice_bannercount_fr12 1 en.wikipedia.org FALSE / FALSE 1374590485 centralnotice_bucket 0-4.2 en.wikipedia.org FALSE / FALSE 1373131359 mediaWiki.user.bucket%3Aext.articleFeedbackv5%4011-tracking 11%3Aignore en.wikipedia.org FALSE / FALSE 1373131359 mediaWiki.user.bucket%3Aext.articleFeedbackv5%405-links 5%3AX en.wikipedia.org FALSE / FALSE 1373131359 mediaWiki.user.bucket%3Aext.articleFeedbackv5%406-form 6%3A6 en.wikipedia.org FALSE / FALSE 0 uls-previous-languages %5B%22en%22%5D ------------GI3gL6Ef1GI3cH2KM7ei4cH2gL6ei4 Content-Disposition: form-data; name="Upload" Submit Query ------------GI3gL6Ef1GI3cH2KM7ei4cH2gL6ei4-- #########################True/True ------------gL6GI3Ij5Ef1ei4Ef1ae0ei4Ef1gL6 Content-Disposition: form-data; name="Filename" Test.txt ------------gL6GI3Ij5Ef1ei4Ef1ae0ei4Ef1gL6 Content-Disposition: form-data; name="Filedata"; filename="Test.txt" Content-Type: application/octet-stream This is text found instead Test.txt ------------gL6GI3Ij5Ef1ei4Ef1ae0ei4Ef1gL6 Content-Disposition: form-data; name="Upload" Submit Query ------------gL6GI3Ij5Ef1ei4Ef1ae0ei4Ef1gL6-- #########################False/True ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ item.getContentType(): null item.getName: null item.getSize: 10 item.getString: Cookie.txt item.getFieldName: Filename item.isFormField: true item.isInMemory: true item.toString(): name=null, StoreLocation=C:\test\jboss-eap-5.1\jboss-as\server\test\tmp\upload__32478800_14078614409__7ffa_00000000.tmp, size=10bytes, isFormField=true, FieldName=Filename ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ item.getContentType(): application/octet-stream item.getName: Cookie.txt item.getSize: 0 item.getString: item.getFieldName: Filedata item.isFormField: false item.isInMemory: true item.toString(): name=Cookie.txt, StoreLocation=C:\test\jboss-eap-5.1\jboss-as\server\test\tmp\upload__32478800_14078614409__7ffa_00000001.tmp, size=0bytes, isFormField=false, FieldName=Filedata ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ item.getContentType(): null item.getName: null item.getSize: 12 item.getString: Submit Query item.getFieldName: Upload item.isFormField: true item.isInMemory: true item.toString(): name=null, StoreLocation=C:\test\jboss-eap-5.1\jboss-as\server\test\tmp\upload__32478800_14078614409__7ffa_00000002.tmp, size=12bytes, isFormField=true, FieldName=Upload #########################False/True ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ item.getContentType(): null item.getName: null item.getSize: 8 item.getString: Test.txt item.getFieldName: Filename item.isFormField: true item.isInMemory: true item.toString(): name=null, StoreLocation=C:\test\jboss-eap-5.1\jboss-as\server\test\tmp\upload_6fd3dea8_140789cbb78__7ffa_00000003.tmp, size=8bytes, isFormField=true, FieldName=Filename ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ item.getContentType(): application/octet-stream item.getName: Test.txt item.getSize: 0 item.getString: item.getFieldName: Filedata item.isFormField: false item.isInMemory: true item.toString(): name=Test.txt, StoreLocation=C:\test\jboss-eap-5.1\jboss-as\server\test\tmp\upload_6fd3dea8_140789cbb78__7ffa_00000004.tmp, size=0bytes, isFormField=false, FieldName=Filedata ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ item.getContentType(): null item.getName: null item.getSize: 12 item.getString: Submit Query item.getFieldName: Upload item.isFormField: true item.isInMemory: true item.toString(): name=null, StoreLocation=C:\test\jboss-eap-5.1\jboss-as\server\test\tmp\upload_6fd3dea8_140789cbb78__7ffa_00000005.tmp, size=12bytes, isFormField=true, FieldName=Upload #########################True/False [accept:text/* content-type:multipart/form-data; boundary=----------Ij5KM7ae0Ef1GI3ei4ei4gL6GI3ei4 user-agent:Shockwave Flash host:localhost content-length:1019 connection:Keep-Alive cache-control:no-cache cookie:JSESSIONID=C8FF29BF4253B2E9B9EEF3360F83EB74 ] #########################True/False [accept:text/* content-type:multipart/form-data; boundary=----------GI3cH2ei4KM7ei4GI3GI3KM7gL6ae0 user-agent:Shockwave Flash host:localhost content-length:449 connection:Keep-Alive cache-control:no-cache cookie:JSESSIONID=B4D506EF25DA8FD0D5B11DBA98B2B21D ] #########################False/False ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ item.getContentType(): null item.getName: null item.getSize: 10 item.getString: Cookie.txt item.getFieldName: Filename item.isFormField: true item.isInMemory: true item.toString(): name=null, StoreLocation=C:\test\jboss-eap-5.1\jboss-as\server\test\tmp\upload_50024124_140787caa99__7ffa_00000000.tmp, size=10bytes, isFormField=true, FieldName=Filename ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ item.getContentType(): application/octet-stream item.getName: Cookie.txt item.getSize: 0 item.getString: item.getFieldName: Filedata item.isFormField: false item.isInMemory: true item.toString(): name=Cookie.txt, StoreLocation=C:\test\jboss-eap-5.1\jboss-as\server\test\tmp\upload_50024124_140787caa99__7ffa_00000001.tmp, size=0bytes, isFormField=false, FieldName=Filedata ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ item.getContentType(): null item.getName: null item.getSize: 12 item.getString: Submit Query item.getFieldName: Upload item.isFormField: true item.isInMemory: true item.toString(): name=null, StoreLocation=C:\test\jboss-eap-5.1\jboss-as\server\test\tmp\upload_50024124_140787caa99__7ffa_00000002.tmp, size=12bytes, isFormField=true, FieldName=Upload #########################False/False ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ item.getContentType(): null item.getName: null item.getSize: 8 item.getString: Test.txt item.getFieldName: Filename item.isFormField: true item.isInMemory: true item.toString(): name=null, StoreLocation=C:\test\jboss-eap-5.1\jboss-as\server\test\tmp\upload_c1b3312_14078bd7c03__7ffa_00000000.tmp, size=8bytes, isFormField=true, FieldName=Filename ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ item.getContentType(): application/octet-stream item.getName: Test.txt item.getSize: 0 item.getString: item.getFieldName: Filedata item.isFormField: false item.isInMemory: true item.toString(): name=Test.txt, StoreLocation=C:\test\jboss-eap-5.1\jboss-as\server\test\tmp\upload_c1b3312_14078bd7c03__7ffa_00000001.tmp, size=0bytes, isFormField=false, FieldName=Filedata ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ item.getContentType(): null item.getName: null item.getSize: 12 item.getString: Submit Query item.getFieldName: Upload item.isFormField: true item.isInMemory: true item.toString(): name=null, StoreLocation=C:\test\jboss-eap-5.1\jboss-as\server\test\tmp\upload_c1b3312_14078bd7c03__7ffa_00000002.tmp, size=12bytes, isFormField=true, FieldName=Upload </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload