PDA

View Full Version : File upload sends null to server



theyang
7 Apr 2008, 4:07 AM
Hi,

I am trying to send a file to server. I am running the exact samples shown in http://extjs.com/forum/showthread.php?p=144229

I see the request but while debugging my asp.net code I see that the request only contains one parameter called 'null'. No signs of the file.

Can someone please help?

Thank you.

dj
7 Apr 2008, 4:21 AM
show us some code (client/server) otherwise it's hard to tell what's going wrong.

theyang
7 Apr 2008, 4:44 AM
Ok here is the js code:


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="../../lib/ext/resources/css/ext-all.css">

<script type="text/javascript" src="../../lib/ext/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="../../lib/ext/ext-all-debug.js"></script>


<!-- next data can be generated by server -->
<script type="text/javascript">
var formData = {
textid:'Value for Text Field'
,areaid:'Value for Text Area'
}
</script>

<script type="text/javascript">

Ext.BLANK_IMAGE_URL = '../../lib/ext/resources/images/default/s.gif';
Ext.onReady(function() {
Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'side';


var win = new Ext.Window({
width:500
,id:'winid'
,height:300
,layout:'fit'
,border:false
,closable:false
,renderTo:Ext.getBody()
,frame:true
,title:Ext.get('title').dom.innerHTML
,closable:true
,items:[{
xtype:'form'
,id:'formid'
,defaultType:'textfield'
,frame:true
,url:'http://localhost:52412/handlers/fileuploadhandler.ashx'
,method:'post'
,fileUpload:true
,items:[{
fieldLabel:'Text Field'
,id:'textid'
},{
fieldLabel:'Text Area'
,id:'areaid'
,xtype:'textarea'
},{
fieldLabel:'Upload'
,id:'uploadid'
,xtype:'textfield'
,inputType:'file'
}]
,buttons:[{
text:'Submit'
,handler:function(btn) {
Ext.getCmp('formid').getForm().submit({
success:function(form, result) {
console.info(Ext.decode(result.response.responseText));
}
,failure:function() {
console.error(arguments);
}
});
}
}]
}]
});
win.on('show', function() {
win.items.itemAt(0).getForm().loadRecord({data:formData});
});
win.show();
});
</script>
<title id="title">Form Example</title>
</head>
<body>
</body>
</html>

FileUploadHandler.ashx doesn't contain any code because I am just debugging at the server side. Here is the contents of Request when I submit the form (irrelevant params omitted):

Form {null&}
Params {null&&.ASPXANONYMOUS=UGiU0xPPyAEkAAAAODhlMGY4Y2MtMWZjMS00NWE2LTkwN2UtZWQ2NmIwNzdhZDYwvGmcdbxWpY4UkQIiUtlodgJUXwk1&ALL_HTTP=HTTP_CACHE_CONTROL%3ano-cache%0d%0aHTTP_CONNECTION%3aKeep-Alive%0d%0aHTTP_CONTENT_LENGTH%3a5%0d%0aHTTP_CONTENT_TYPE%3aapplication%2fx-www-form-urlencoded%0d%0aHTTP_ACCEPT%3a*%2f*%0d%0aHTTP_ACCEPT_ENCODING%3agzip%2c+deflate%0d%0aHTTP_ACCEPT_LANGUAGE%3atr-TR%0d%0aHTTP_COOKIE%3a.ASPXANONYMOUS%3dUGiU0xPPyAEkAAAAODhlMGY4Y2MtMWZjMS00NWE2LTkwN2UtZWQ2NmIwNzdhZDYwvGmcdbxWpY4UkQIiUtlodgJUXwk1%0d%0aHTTP_HOST%3alocalhost%3a52412%0d%0aHTTP_REFERER%3ahttp%3a%2f%2flocalhost%3a52412%2fDefault.aspx%0d%0aHTTP_USER_AGENT%3aMozilla%2f4.0+(compatible%3b+MSIE+7.0%3b+Windows+NT+6.0%3b+SLCC1%3b+.NET+CLR+2.0.50727%3b+.NET+CLR+3.0.04506%3b+.NET+CLR+3.5.21022)%0d%0aHTTP_X_REQUESTED_WITH%3aXMLHttpRequest%0d%0aHTTP_UA_CPU%3ax86%0d%0a&ALL_RAW=Cache-Control%3a+no-cache%0d%0aConnection%3a+Keep-Alive%0d%0aContent-Length%3a+5%0d%0aContent-Type%3a+application%2fx-www-form-urlencoded%0d%0aAccept%3a+*%2f*%0d%0aAccept-Encoding%3a+gzip%2c+deflate%0d%0aAccept-Language%3a+tr-TR%0d%0aCookie%3a+.ASPXANONYMOUS%3dUGiU0xPPyAEkAAAAODhlMGY4Y2MtMWZjMS00NWE2LTkwN2UtZWQ2NmIwNzdhZDYwvGmcdbxWpY4UkQIiUtlodgJUXwk1%0d%0aHost%3a+localhost%3a52412%0d%0aReferer%3a+http%3a%2f%2flocalhost%3a52412%2fDefault.aspx%0d%0aUser-Agent%3a+Mozilla%2f4.0+(compatible%3b+MSIE+7.0%3b+Windows+NT+6.0%3b+SLCC1%3b+.NET+CLR+2.0.50727%3b+.NET+CLR+3.0.04506%3b+.NET+CLR+3.5.21022)%0d%0ax-requested-with%3a+XMLHttpRequest%0d%0aUA-CPU%3a+x86%0d%0a&APPL_MD_PATH=&APPL_PHYSICAL_PATH=D%3a%5cProjects%5cproject93.com%5c&AUTH_TYPE=NTLM&AUTH_USER=WIN-XFV8TEEC60T%5cAdministrator&AUTH_PASSWORD=&LOGON_USER=WIN-XFV8TEEC60T%5cAdministrator&REMOTE_USER=WIN-XFV8TEEC60T%5cAdministrator&CERT_COOKIE=&CERT_FLAGS=&CERT_ISSUER=&CERT_KEYSIZE=&CERT_SECRETKEYSIZE=&CERT_SERIALNUMBER=&CERT_SERVER_ISSUER=&CERT_SERVER_SUBJECT=&CERT_SUBJECT=&CONTENT_LENGTH=5&CONTENT_TYPE=application%2fx-www-form-urlencoded&GATEWAY_INTERFACE=&HTTPS=&HTTPS_KEYSIZE=&HTTPS_SECRETKEYSIZE=&HTTPS_SERVER_ISSUER=&HTTPS_SERVER_SUBJECT=&INSTANCE_ID=&INSTANCE_META_PATH=&LOCAL_ADDR=127.0.0.1&PATH_INFO=%2fHandlers%2fFileUploadHandler.ashx&PATH_TRANSLATED=D%3a%5cProjects%5cproject93.com%5cHandlers%5cFileUploadHandler.ashx&QUERY_STRING=&REMOTE_ADDR=127.0.0.1&REMOTE_HOST=127.0.0.1&REMOTE_PORT=&REQUEST_METHOD=POST&SCRIPT_NAME=%2fHandlers%2fFileUploadHandler.ashx&SERVER_NAME=localhost&SERVER_PORT=52412&SERVER_PORT_SECURE=0&SERVER_PROTOCOL=HTTP%2f1.1&SERVER_SOFTWARE=&URL=%2fHandlers%2fFileUploadHandler.ashx&HTTP_CACHE_CONTROL=no-cache&HTTP_CONNECTION=Keep-Alive&HTTP_CONTENT_LENGTH=5&HTTP_CONTENT_TYPE=application%2fx-www-form-urlencoded&HTTP_ACCEPT=*%2f*&HTTP_ACCEPT_ENCODING=gzip%2c+deflate&HTTP_ACCEPT_LANGUAGE=tr-TR&HTTP_COOKIE=.ASPXANONYMOUS%3dUGiU0xPPyAEkAAAAODhlMGY4Y2MtMWZjMS00NWE2LTkwN2UtZWQ2NmIwNzdhZDYwvGmcdbxWpY4UkQIiUtlodgJUXwk1&HTTP_HOST=localhost%3a52412&HTTP_REFERER=http%3a%2f%2flocalhost%3a52412%2fDefault.aspx&HTTP_USER_AGENT=Mozilla%2f4.0+(compatible%3b+MSIE+7.0%3b+Windows+NT+6.0%3b+SLCC1%3b+.NET+CLR+2.0.50727%3b+.NET+CLR+3.0.04506%3b+.NET+CLR+3.5.21022)&HTTP_X_REQUESTED_WITH=XMLHttpRequest&HTTP_UA_CPU=x86}

You can see the form values only contain 'null&', no param name and no param value...
Thank you.

dj
7 Apr 2008, 4:52 AM
You should probably figure out, how ASP can handle file uploads. A file upload is not a normal POST request. It is encoded as MIME multipart/form-data.

I don't know ASP so I have no clue how to do that.

The JavaScript looks correct.

theyang
7 Apr 2008, 5:14 AM
You are absolutely right. ;)

I paste the C# code here, incase someone needs it.


public void ProcessRequest(HttpContext context)
{
if (context.request.Files.Count > 0)
context.request.Files[0].SaveAs(file_name);
}


Thanks.