PDA

View Full Version : ajax post with a fileuploadfield



plmdoctor
17 Mar 2011, 5:56 PM
I am trying to do something similar as the File Upload Form example. There is a fileuploadfield and some other fields (combobox and text). But it seems I can either upload the file or post the field values. Not both. This is what I found in the API docs



(http://dev.sencha.com/deploy/dev/docs/output/Ext.form.BasicForm.html#Ext.form.BasicForm-fileUpload)File uploads (http://dev.sencha.com/deploy/dev/docs/output/Ext.form.BasicForm.html#Ext.form.BasicForm-fileUpload) are not performed using Ajax submission, that is they are not performed using XMLHttpRequests. Instead the form is submitted in the standard manner with the DOM <form> element temporarily modified to have its (http://dev.sencha.com/deploy/dev/docs/output/Ext.form.BasicForm.html#Ext.form.BasicForm-fileUpload)target (http://www.w3.org/TR/REC-html40/present/frames.html#adef-target) set to refer to a dynamically generated, hidden <iframe> which is inserted into the document but removed after the return data has been gathered.
(http://dev.sencha.com/deploy/dev/docs/output/Ext.form.BasicForm.html#Ext.form.BasicForm-fileUpload)

Any suggestions on how I can get the file and field values up to the server? They could be in separate posts.

jratcliff
17 Mar 2011, 6:08 PM
your fields and the uploaded attachment should both be in the post. You just probably have to modify your server side code to deal with extracting the form fields/values differently since the form posted is using the multipart/form-data encoding instead of the default application/x-www-form-urlencoded content type.

If you read further down in the docs for the fileUpload config property notice the last sentence:


Be aware that file upload packets are sent with the content type multipart/form and some server technologies (notably JEE) may require some custom processing in order to retrieve parameter names and parameter values from the packet content.

plmdoctor
17 Mar 2011, 7:11 PM
That is where I am struggling. I am used to calling request.getParameter("xxx") or request.getParameterValues(key). This "special handling" for the parameters has got me. I am handling the file stream OK.

plmdoctor
17 Mar 2011, 7:21 PM
OK. I am finding stuff on the internet about multipart/form-data. Thanks for turning me on to that.

plmdoctor
18 Mar 2011, 6:39 AM
Building this out further... In addition to the fileuploadfield there are some dynamic comboboxes. I end up posting a few times due to dependancies. Every time I post am I sending the file to the server? Is there a way to post without sending the file every time?