Uploading file from a USB Storage

Hi Guys

Is there any sample code(or a solution) for uploading a file(actually transferring a large file ) to a web server, from a usb storage using netmf?

my board is Fez Spider

how can i prevent an insufficient resources?

i have to load a file into a memory and i only have 32 mbs of ram !
how can i load a larger file to upload to a web server ?

sorry for my bad english

I assume the USB storage is connected to the NETMF device and the WebServer is somewhere in the internet.

I can not help you with the HTTP stuff, but I can assist you with uploading the file.
Normally you have some kind of stream where you write your data to (uploadStream).
And you have a fileStream to the file on USB device.
Then you create a ‘small’ buffer (lets say about 10k) to which you read from file and the write to uploadStream.


// get the uploadStream from HTTP request, FTP, ...
var uploadStream =  ...
//open file
using (var fileSTream = new FileStream("path to file"))
{
   var buffer = new byte[10 * 1024]; // you can adjust the buffer size to get optimal performance
  // read 1st chunk
   int cnt = fileStream.Read(buffer, 0, buffer.Length);
   while(cnt > 0)
   {
      // write to upload stream
      uploadStream.Write(buffer, 0, cnt);

      // read next chunk
      cnt = fileStream.Read(buffer, 0, buffer.Length);
   }
}
// done, close/finalize uploadStream if necessary

I hope this helps.
(code is actually not checked for syntax errors, just typed it directly in here)

1 Like

Thanks for your useful response.

actually i am looking for a solution to uploading very large file over HTTP to our web server
buffering is good for reading large file but how can we send this splitted packets to our server ?