PDA

View Full Version : fileUpload: Unable to passing additional parameter on a submit



Boynton
10 Aug 2009, 3:54 PM
Hello,
Parameters are not being passed in the request when doing a form submit for a form that has a fileUpload: true .

In firebug I see the values being set but when I get to the java action and inspect the request parameters there are no additional values other than the uploaded file.
I've also tried hidden fields in the form but that didn't work.
I also tried to set the values on the form (see bellow..)

Using ext 2.0.2

Any ideas??
Thank You.
-Boynton.

js follows..

Ext.ux.FileUploadDialog = function()
{

var fp = new Ext.FormPanel({
fileUpload: true,
url: 'uploadConfigurationFile.htm',
fileType: '',
deviceName: '',
width: 500,
frame: true,
title: 'File Upload Form',
autoHeight: true,
bodyStyle: 'padding: 10px 10px 0 10px;',
labelWidth: 50,
defaults: {
anchor: '95%',
allowBlank: false,
msgTarget: 'side'
},
items: [{xtype:"textfield",inputType:'file',fieldLabel:"File",name:"file",allowBlank:false}],
buttons: [
{
text: 'Upload',
handler: function(){
if(fp.getForm().isValid()){
fp.getForm().enctype='multipart/form-data';
fp.getForm().encoding='multipart/form-data';
fp.getForm().id=fp.deviceName;
fp.getForm().type=fp.fileType;
fp.getForm().submit({
params:{id: fp.deviceName, type: fp.fileType},
success: function(f,a){
Ext.Msg.alert('worked');
},
failure: function(f,a){
Ext.Msg.alert('not worked');
}
});
}
}
}
,
]
});

return Ext.apply(new Ext.Window({
width:500,
height:300,
closeAction:'hide',
plain: true,
modal: true,
items: fp,
id:'fileUploadWindow'

}),{
showDialog: function(fileType, deviceName) {
fp.fileType = fileType;
fp.deviceName = deviceName;
this.show();
}
});


}();

josiahstaggs
10 Aug 2009, 5:07 PM
Hi,

I'm seeing the same EXACT error. Does anyone know what the problem might be?

evant
10 Aug 2009, 5:09 PM
getForm() returns a BasicForm object, not the dom form.

Boynton
28 Aug 2009, 12:15 PM
I'm using http://commons.apache.org/fileupload/using.html
see code abstract below..

// Create a factory for disk-based file items
DiskFileItemFactory factory = new DiskFileItemFactory();
//factory.setFileCleaningTracker(fileCleaningTracker);

// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload(factory);

// Parse the request
List <FileItem> items = upload.parseRequest(request);
Iterator <FileItem>iter = items.iterator();

String type = "";
String fileName = "";
File file = null;

while (iter.hasNext()){
FileItem item = (FileItem) iter.next();

if (item.isFormField() && item.getFieldName().equalsIgnoreCase("type")) {
type =item.getString();
}

if(!item.isFormField() && item.getFieldName().equalsIgnoreCase("file")) {
//removes path information.
fileName = FilenameUtils.getName(item.getName());
file = new File(fileName);
item.write(file);

....
Thanks.

raj_plays
25 Mar 2010, 11:45 PM
Hi,
I have a form with fileUpload: true.
The file upload works fine but I want to pass a textfield's value along with the file to my server side.
How can I do this?
I am using Ext 3.1.1

Animal
26 Mar 2010, 12:43 AM
It's not in the form that you are submitnig?

Then add its value to the params option.

Animal
26 Mar 2010, 12:43 AM
It's not in the form that you are submitting?

Then add its value to the params option.

raj_plays
26 Mar 2010, 2:57 AM
Animal,
My form contains a FileUploadField and a TextField.
The form has fileUpload: true. With this config, I can access the file on my server side but not the text field.
If I remove the 'fileUpload: true' option, then I can access the text field.
How can I get both?

Animal
26 Mar 2010, 3:54 AM
They are both submitted. This is a question about your server side, not ExtJS.

raj_plays
26 Mar 2010, 10:58 AM
Thank you, Animal.

Indeed the form gets submitted along with all its items but the way to extract them on the server is different when fileUpload is turned on.
In ASP, the textfield value can be accessed as...



HttpContext postedContext = HttpContext.Current;
string id=postedContext.Request.Form["id"];

and the uploaded file as


postedContext.Request.Files[0];

Nxs
30 Aug 2013, 6:53 AM
Thank you, Animal.

Indeed the form gets submitted along with all its items but the way to extract them on the server is different when fileUpload is turned on.
In ASP, the textfield value can be accessed as...



HttpContext postedContext = HttpContext.Current;
string id=postedContext.Request.Form["id"];

and the uploaded file as


postedContext.Request.Files[0];


You saved my day !!! THANKS =D>