PDA

View Full Version : [OPEN] File upload gives wrong file names. Characters encoding issue?



ecanraf
18 Feb 2011, 8:09 AM
Hello,

I have a xtjs form that submits a file to the server. The header of my HTML file looks like this:

<meta content="text/html;charset=UTF-8" http-equiv="content-type">

In my form I have a texfield with the inputType: 'file' configuration (the full form code is bellow).

When running the page, if I select a file with normal characters in its name (e.g. "hola.jpg") everything works OK and the file is transfered to the server. However, if I pick a file from my system with a name like this: "cañón.jpg" which contains utf-8 character in it, then the server receives wrong characters in the file name and it meses up my application.

It seems to me that extjs is changing the charset to ASCII or something differently when submitting, but I don't know if it is a bug, or if I'm missing some configuration in my code.

I'm using extjs 3.3.1

full code bellow:




function ventanaNuevaFoto(){
Ext.QuickTips.init();

var wnf = new Ext.Window({
title: 'Añadir foto',
width: 350,
height: 140,
layout: 'fit',
modal: true,
items: [{
xtype: 'form',
fileUpload: true,
name: 'picture',
id: 'fnf',
url: '/obras/'+obra_id+'/crearfoto/'+mes_visualizado,
frame: true,
items: [
{
xtype: 'textfield',
fieldLabel: 'Foto',
name: 'photo',
id: 'campoFoto',
width: 140,
allowBlank: false,
inputType: 'file'
},{
xtype: 'textfield',
fieldLabel: 'Descripción',
name: 'descripcion',
id: 'campoDesc',
width: 140,
allowBlank: false
}
,{
xtype: 'hidden',
name: 'token_r',
value: token_r_var
}
]
}],
buttons: [{
text: 'Cancelar',
handler: function(){
wnf.close(this);
}
},{
text: 'Enviar',
disabled: false,
handler: function(){
wnf.getComponent('fnf').getForm().doAction(
'submit',
{
success: function(f,a){
wnf.disable();
window.location = '/obras/'+obra_id+'/fotos/'+mes_visualizado;
},
failure: function(f,a){
if (a.failureType === Ext.form.Action.CLIENT_INVALID) {
Ext.Msg.alert('Error', 'Por favor rellene los dos campos correctamente');
}else{
resp = Ext.decode(a.response.responseText);
Ext.Msg.alert('Alerta', resp.msg);
}
},
waitMsg: 'Por favor espere',
waitTitle: 'Procesando'
}
);
}
}
]
});

wnf.show();
};

Condor
18 Feb 2011, 8:16 AM
Specifying the Content-type as a meta tag doesn't make the HTML file UTF-8! Your server needs to specify the Content-type in the response header.

ecanraf
18 Feb 2011, 4:17 PM
You are right. I was trying locally with my test server on my windows machine. Once I placed the application in the production server (apache @ linux) headers are being placed correctly and the problem is gone.

Thanks for the hint.