PDA

View Full Version : Upload files to a servlet



Trio87
23 Jun 2010, 7:42 AM
Hi all,
i have to upload 1 or 2 files to a server using a multipart/form-data.
i followed the example found here: http://www.sencha.com/deploy/dev/examples/index.html
but i cannot use Ext.ux

I tryed this solution:


var uploadForm = new Ext.form.FormPanel({
fileupload: true,
isUpload: true,
method: POST,
enctype: 'multipart/form-data',
url: SERVLETURL,
frame: true,
title: 'File Upload Form',
bodyStyle: 'padding: 10px 10px 0 10px;',
labelWidth: 50,
items: [{
inputType: 'file',
xtype: 'textfield',
id: 'teifile',
fieldLabel: 'TEI',
name: 'teipath',
},{
inputType: 'file',
xtype: 'textfield',
id: 'dtdfile',
fieldLabel: 'DTD',
name: 'dtdpath',
}],
buttons: [{
text: TransformInNormalText('UpLoad'),
handler: function(){
if(uploadForm.getForm().isValid()){
uploadForm.getForm().submit({
url: AVAILABLEDOCSURL,
waitMsg: 'Uploading file(s)',
success: function(uploadForm, o){
msg('Success', 'Processed file "'+o.result.file+'" on the server');
},
failure: function(uploadForml, o){
msg('Failure', 'Failed to upload "'+o.result.file+'" on the server');
}
});
}
}//function handler
}]//buttons

});//formpanel

Using this when i press the button, a "waiting" window appears and never go away (and, of course, neither failure's msg or success' msg appears)

I tested the server using a normal html form and it works.

Can someone tell me where is the mistake?
Thanks all,
Trio.

carol.ext
23 Jun 2010, 8:05 AM
Did you try fileUpload instead of fileupload ?

Trio87
23 Jun 2010, 8:44 AM
it was that...
I am dumb ~ I am dumb ~ I am dumb ~ I am dumb ~ I am dumb ~
I am dumb ~ I am dumb ~ I am dumb ~ I am dumb ~ I am dumb ~
I am dumb ~ I am dumb ~ I am dumb ~ I am dumb ~ I am dumb ~
I am dumb ~ I am dumb ~ I am dumb ~ I am dumb ~ I am dumb ~
I am dumb ~ I am dumb ~ I am dumb ~ I am dumb ~ I am dumb ~
I am dumb ~ I am dumb ~ I am dumb ~ I am dumb ~ I am dumb ~

Thank you very much :)

now the upload works but the "waiting" window never disappear...
How can I fix it?

Animal
23 Jun 2010, 1:11 PM
Content-Type ? As described in the docs?

Trio87
24 Jun 2010, 2:37 AM
Sorry animal...can you be more clear please?

Animal
24 Jun 2010, 3:11 AM
http://www.sencha.com/deploy/dev/docs/?class=Ext.form.BasicForm&member=fileUpload

hbeing123
24 Jun 2010, 1:44 PM
I've been having the same problem today... I just don't understand it... I have fileUpload:true which should mean the content is sent has 'multipart/form-data' ,but coldfusion keeps on saying invalid content type... I've made the content return as text/html and it's still not working...

hbeing123
24 Jun 2010, 1:49 PM
uploadform = new Ext.FormPanel({
fileUpload: true,

method: 'POST',

iconCls:'icon-application_home',
autoScroll:true,
labelWidth: 90,
frame:false,
border:false,
bodyStyle:'padding:5px 5px 0;',
labelAlign: 'top',
bbar:[uploadbutton,helpbutton],
items: [importcombo,
{
inputType: 'file',
xtype: 'textfield',
id: 'zipfileupload',
fieldLabel: 'CSV Zip File',
name: 'zipfileupload'
},import_title]
});


function submitForm() {

uploadform.getForm().url = model_location + 'doZipUpload.cfm';
//uploadform.getForm().baseParams = {regioncode:selectedregioncode};
uploadform.getForm().submit({waitMsg:'saving....'});

};



and the CF:



<cfcontent type="text/html">
<cfprocessingdirective suppresswhitespace="true">


<cfset xmsg = structnew()>
<cfset xmsg.success = "true">
<cfset xmsg.message = "Test Uploaded">
<cfset xmsg.treepath = "">

<cfset errorslist = "">
<cfset qt = "#chr(34)#">

<cfscript>
theFilename="test.zip";
theDir=GetDirectoryFromPath(GetCurrentTemplatePath()) & "temp\";
theFile=theDir & theFilename;
</cfscript>

<cffile action="UPLOAD" filefield="zipfileupload" destination="#theDir#" attributes="normal" nameconflict="MAKEUNIQUE">


</cfprocessingdirective>




and the error is 500, Invalid Content Type ''

hbeing123
24 Jun 2010, 2:00 PM
OK, making some headway with this... but it's quite strange, I discovered CF was hitting back with invalid content type message, but in fact the directory didn't exist... once I added it, the error stopped coming...