Error with (large) fileupload using HttpWebRequest

  • Thread starter Thread starter cyberco
  • Start date Start date
C

cyberco

Using:
Windows Mobile 5 PPC
..NetCF 2.0

I'm uploading files via the cellular connection (GPRS). This works with
files up to around 2Mb. With larger files the transfer is suddenly
aborted after around 2Mb has been uploaded. No message, nothing, not a
byte leaves the phone anymore. The only way to get out of that
situation is to reboot the device completely (by removing the battery).
I'm using the following code.

======================================================
FileStream tmpFileStream = tmpFileStream = new FileStream(appPath +
Properties.Resources.tmpUploadFile, FileMode.Open, FileAccess.Read);
HttpWebRequest req =
(HttpWebRequest)WebRequest.Create("http://bla/bla");
req.Method = "POST";
req.ContentType = "multipart/form-data; boundary=0123456789";
req.ContentLength = tmpFileStream.Length;

// Retrieve request stream and wrap in StreamWriter
Stream reqStream = req.GetRequestStream();
BinaryWriter bsw = new BinaryWriter(reqStream);
byte[] bytes = new byte[tmpFileStream.Length];
tmpFileStream.Read(bytes, 0, (int)tmpFileStream.Length);
bsw.Write(bytes);
bsw.Close();
tmpFileStream.Close();
======================================================

Does anybody here have the same experience?
What am I doing wrong?
Should I use sockets instead?
 
What webserver are you using? When you use ISS there are some settings
that can limit your filesize in an upload.
Look for MaxRequestEntityAllowed or AspMaxRequestEntityAllowed in
metabase.xml

Jan
 
I'm using Apache + PHP, but both have been configured to accept such
large files. If I upload via the ActiveSync connection everything goes
fine, so it has nothing to do with limitations on the serverside or
limitations in the phone for handling such large files.
 
Using plain sockets solves the problem of the incomplete upload, so
there seems to be a problem with HttpWebRequest.
Of course sockets bring there own issues along: Other than with the
HttpWebRequest class there is no automatic re-attach to the
GSM/GPRS/UMTS network when opening a socket. :(
 
checkout the use DIME in opennetcf library to upload file via attachment,
although this method is outdated.
 
Back
Top