473,414 Members | 1,627 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Uploading large files from an iPAQ

Dan
I'm trying to upload a large binary file from an iPAQ, but am getting
out-of-memory exceptions when I try to convert the byte array containing the
data to a string in order to include it in the StringBuilder object which
represents the http (multipart/form-data mimetype) request. The code I'm
using to read and convert the data is below, and the exception occurs in
ascii.GetString. The file is about 9mb, and I've got plenty of free memory
(according the system monitor in the iPAQ, I've got 38.64MB free storage,
and 61.85MB free program memory). Does anyone have any suggestions?
Thanks...Dan

try
{
fs = new FileStream(m_FileName, FileMode.Open, FileAccess.Read);
r = new BinaryReader(fs);
if (fs.Length > int.MaxValue)
throw new Exception("The ServletRequest library currently will not
upload files greater than " + int.MaxValue + " bytes. " + m_FileName + "
contains " + fs.Length + "
bytes.");
byte[] fileContent = r.ReadBytes((int) fs.Length);
ASCIIEncoding ascii = new ASCIIEncoding();
return ascii.GetString(fileContent, 0, fileContent.Length);
}
catch (Exception e)
{
throw new Exception("Error retrieving filecontent from " + m_FileName,
e);
}
Nov 16 '05 #1
4 1401
CE's memory model doesn't allow you to use all the "free" memory you see for
heap allocations. Packetize the send.

-Chris
"Dan" <da*@dontspamme.com> wrote in message
news:uC**************@TK2MSFTNGP15.phx.gbl...
I'm trying to upload a large binary file from an iPAQ, but am getting
out-of-memory exceptions when I try to convert the byte array containing the data to a string in order to include it in the StringBuilder object which
represents the http (multipart/form-data mimetype) request. The code I'm
using to read and convert the data is below, and the exception occurs in
ascii.GetString. The file is about 9mb, and I've got plenty of free memory (according the system monitor in the iPAQ, I've got 38.64MB free storage,
and 61.85MB free program memory). Does anyone have any suggestions?
Thanks...Dan

try
{
fs = new FileStream(m_FileName, FileMode.Open, FileAccess.Read);
r = new BinaryReader(fs);
if (fs.Length > int.MaxValue)
throw new Exception("The ServletRequest library currently will not
upload files greater than " + int.MaxValue + " bytes. " + m_FileName + "
contains " + fs.Length + "
bytes.");
byte[] fileContent = r.ReadBytes((int) fs.Length);
ASCIIEncoding ascii = new ASCIIEncoding();
return ascii.GetString(fileContent, 0, fileContent.Length);
}
catch (Exception e)
{
throw new Exception("Error retrieving filecontent from " + m_FileName,
e);
}

Nov 16 '05 #2
Dan
Is there a way to find out how much memory you're allowed to use before
allocating it?

"Chris Tacke, eMVP" <ct****@spamfree-opennetcf.org> wrote in message
news:O4**************@TK2MSFTNGP11.phx.gbl...
CE's memory model doesn't allow you to use all the "free" memory you see for heap allocations. Packetize the send.

-Chris
"Dan" <da*@dontspamme.com> wrote in message
news:uC**************@TK2MSFTNGP15.phx.gbl...
I'm trying to upload a large binary file from an iPAQ, but am getting
out-of-memory exceptions when I try to convert the byte array containing

the
data to a string in order to include it in the StringBuilder object which represents the http (multipart/form-data mimetype) request. The code I'm using to read and convert the data is below, and the exception occurs in
ascii.GetString. The file is about 9mb, and I've got plenty of free

memory
(according the system monitor in the iPAQ, I've got 38.64MB free storage, and 61.85MB free program memory). Does anyone have any suggestions?
Thanks...Dan

try
{
fs = new FileStream(m_FileName, FileMode.Open, FileAccess.Read);
r = new BinaryReader(fs);
if (fs.Length > int.MaxValue)
throw new Exception("The ServletRequest library currently will not
upload files greater than " + int.MaxValue + " bytes. " + m_FileName + "
contains " + fs.Length + " bytes.");
byte[] fileContent = r.ReadBytes((int) fs.Length);
ASCIIEncoding ascii = new ASCIIEncoding();
return ascii.GetString(fileContent, 0, fileContent.Length);
}
catch (Exception e)
{
throw new Exception("Error retrieving filecontent from " + m_FileName, e);
}


Nov 16 '05 #3
Not really, and it's even harder here becasue the CF is abstracting the
actual allocation call. If it were me, I'd just chop it into packets around
1k and go that way. Heck, that even provides a progress hook for nice UI
interaction.

-Chris
"Dan" <da*@dontspamme.com> wrote in message
news:u6****************@TK2MSFTNGP10.phx.gbl...
Is there a way to find out how much memory you're allowed to use before
allocating it?

"Chris Tacke, eMVP" <ct****@spamfree-opennetcf.org> wrote in message
news:O4**************@TK2MSFTNGP11.phx.gbl...
CE's memory model doesn't allow you to use all the "free" memory you see for
heap allocations. Packetize the send.

-Chris
"Dan" <da*@dontspamme.com> wrote in message
news:uC**************@TK2MSFTNGP15.phx.gbl...
I'm trying to upload a large binary file from an iPAQ, but am getting
out-of-memory exceptions when I try to convert the byte array containing
the
data to a string in order to include it in the StringBuilder object which represents the http (multipart/form-data mimetype) request. The code I'm using to read and convert the data is below, and the exception occurs
in ascii.GetString. The file is about 9mb, and I've got plenty of free

memory
(according the system monitor in the iPAQ, I've got 38.64MB free

storage, and 61.85MB free program memory). Does anyone have any suggestions?
Thanks...Dan

try
{
fs = new FileStream(m_FileName, FileMode.Open, FileAccess.Read);
r = new BinaryReader(fs);
if (fs.Length > int.MaxValue)
throw new Exception("The ServletRequest library currently will not upload files greater than " + int.MaxValue + " bytes. " + m_FileName + " contains " + fs.Length
+ " bytes.");
byte[] fileContent = r.ReadBytes((int) fs.Length);
ASCIIEncoding ascii = new ASCIIEncoding();
return ascii.GetString(fileContent, 0, fileContent.Length);
}
catch (Exception e)
{
throw new Exception("Error retrieving filecontent from " + m_FileName, e);
}



Nov 16 '05 #4
Dan
Thanks Chris. BTW, do you know whether it's a good idea to flush the stream
as I'm writing the HTTP request? I'm worried that, if I don't, the buffer
might start getting big.

"Chris Tacke, eMVP" <ct****@spamfree-opennetcf.org> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Not really, and it's even harder here becasue the CF is abstracting the
actual allocation call. If it were me, I'd just chop it into packets around 1k and go that way. Heck, that even provides a progress hook for nice UI
interaction.

-Chris
"Dan" <da*@dontspamme.com> wrote in message
news:u6****************@TK2MSFTNGP10.phx.gbl...
Is there a way to find out how much memory you're allowed to use before
allocating it?

"Chris Tacke, eMVP" <ct****@spamfree-opennetcf.org> wrote in message
news:O4**************@TK2MSFTNGP11.phx.gbl...
CE's memory model doesn't allow you to use all the "free" memory you see
for
heap allocations. Packetize the send.

-Chris
"Dan" <da*@dontspamme.com> wrote in message
news:uC**************@TK2MSFTNGP15.phx.gbl...
> I'm trying to upload a large binary file from an iPAQ, but am
getting > out-of-memory exceptions when I try to convert the byte array containing the
> data to a string in order to include it in the StringBuilder object which
> represents the http (multipart/form-data mimetype) request. The
code I'm
> using to read and convert the data is below, and the exception

occurs in > ascii.GetString. The file is about 9mb, and I've got plenty of free
memory
> (according the system monitor in the iPAQ, I've got 38.64MB free storage,
> and 61.85MB free program memory). Does anyone have any suggestions?
> Thanks...Dan
>
> try
> {
> fs = new FileStream(m_FileName, FileMode.Open, FileAccess.Read);
> r = new BinaryReader(fs);
> if (fs.Length > int.MaxValue)
> throw new Exception("The ServletRequest library currently will not > upload files greater than " + int.MaxValue + " bytes. " + m_FileName
+ " > contains " +
fs.Length +
"
> bytes.");
> byte[] fileContent = r.ReadBytes((int) fs.Length);
> ASCIIEncoding ascii = new ASCIIEncoding();
> return ascii.GetString(fileContent, 0, fileContent.Length);
> }
> catch (Exception e)
> {
> throw new Exception("Error retrieving filecontent from " +

m_FileName,
> e);
> }
>
>



Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Marc | last post by:
Hello, I have a page where i can upload binary file (using the HTML input type=file approach). This works fine for relatively small files (<6MB)) but when files get bigger (13MB) there is a...
9
by: Markus Ernst | last post by:
Hi For a CMS admin tool I would like to provide a possibility to upload large files to a directory on the webserver. As HTTP uploads are limited in file size and also not comfortable in...
6
by: Chamomile | last post by:
can anyone point me to some straightforward information on file uploading without using an html form? That is, direcly from within a php script. if I know the local path etc. to a particular...
3
by: deko | last post by:
Newbie ASP.NET question: Now that I've created an ASP.NET site, how to I get it to my hosting provider? I've developed sites with Dreamweaver MX in the past - with Dreamweaver, it's very...
1
by: David | last post by:
Hello. I can't upload large file with HtmlInputFile control:( Is there any file size limitation in HtmlInputFile control? If yes how can I upload to server large size file? Than you.
2
by: WSE with SSL and large amount of data | last post by:
Hi there, What's the better strategy for uploading large files trough webservices? I can use Dime/WS-Attachments but for files with over 5MB in size, maybe I got some timeout/refuse problems in...
1
by: Steven Berkovitz | last post by:
Hi there, I am having a problem with an ASP.NET 1.1 application running on II6. When uploading large files, the attempt seems to timeout (in the form of a IE DNS error) after about a minute...
7
by: Lad | last post by:
If a user will upload large files via FTP protocol, must the user have an FTP client on his computer or is it possible to use a similar way to "http form" comunication? Or is there another way(...
1
by: =?Utf-8?B?RGFu?= | last post by:
MS won't seem to let me reply to my old post, so I created a new one. The error occurs in all browsers. It's definitely a server issue, not client. The server is not proxied in any way. I tried...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.