Note that there are some explanatory texts on larger screens.

plurals
  1. POFile upload in extjs 4.2 without form.submit()
    primarykey
    data
    text
    <p>I'm trying to upload a file (as of now of any extension) in extjs. I have a model and store. the file upload happens from a window and I dont have a form in the window. All example I tried in the net are with form.submit(). I instead use and Ajax call as below to send the data to the server. </p> <pre><code>Ext.Ajax.request({ url : 'qaf/saveSetupDetails.action', params : { 'data' : recordsToSend }, failure : function(response){ //console.log('error connecting controller'); }, success : function(response){ //console.log('successfully submitted'); } }); </code></pre> <p>The records to send in the data is got as below.</p> <pre><code>var store = Ext.getStore('SomeStore'); var modifiedRecords = store.getModifiedRecords(); var recordsToSend = []; if(modifiedRecords.length &gt; 0){ Ext.each(modifiedRecords, function(record){ recordsToSend.push(record.data);//I'm sure that this is so dump but this is how I do it for other records which are string and not sure how to do it for a file... }); } Ext.USE_NATIVE_JSON = true; recordsToSend = Ext.encode(recordsToSend); </code></pre> <p>While setting the record in the model, I use the below code..</p> <pre><code>var rec = Ext.create('QAF.model.MyModel'); rec.set('modelField',Ext.getCmp('fileUploadCompID').value); </code></pre> <p>I received a 500 status error with the response <code>"Cannot convert value of type [java.lang.String] to required type [org.springframework.web.multipart.commons.CommonsMultipartFile]"</code></p> <p>I'm sure that this is because of the way I set the value to the model as <code>Ext.getCmp('fileUploadCompID').value</code> gives the file name. Please let me know how to set the file to the model and what data type I have to specify for the field in the model.</p> <p>Below is how I try to retrieve the file in the spring controller.</p> <pre><code>@RequestMapping (value = "/qaf/saveSetupDetails.action") public @ResponseBody void saveSetupDetails(@RequestParam CommonsMultipartFile data)throws Exception{ log.info("Enter into saveSetupDetails method..." + data.getOriginalFilename()); } </code></pre> <p>Please let me know what I'm doing wrong and what has to be done to fix this...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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