Upload file to server using Gadgeteer


I have a spider and I’m testing out a few things.

One of them is that I’d like to be able to upload a file to my local webserver from the spider.

For example, say I have an image on my SD card (small enough to fit into Spider RAM) and I want to upload it, are there any code snippets etc. to show how to do this?

I know that there is a WebClient class but it looks like you can only make GET requests for URLs using this, is there any way to upload data? I’m assuming you’d open some sort of stream and send it over somehow but I can’t see how.

Thanks for your time.

HTTP allows for PUT that contains payload - you just need to be able to handle that at the web server. search here for multipart mime.

NETMF comes with a FTP Client.
The server was not very stable, but I made a improved version here on Codeshare.
Don’t know how good the Client works.

I also used this as a starter for my own ftp client class and this works pretty stable during the testing.
I still need to add some more commands and proper error handling for some situations but when finished i post this on the codeshare.

Thanks for the responses everyone.

I’ve managed to get it working to some extent, basically by creating a POSTContent instance with byte[] and then sending using an HttpRequest.

I have some simple PHP code on the server side that uses file_get_contents() and file_put_contents() to take “php://input” and dump it into a .jpeg file. I’ve viewed the files it creates and this works fine.

My problem is, I want to be able to send form data with the file (like you can with an HTML form). I’ve used POSTContent to create an instance with a key/value dictionary. And then using PHP pulled these out with $_POST.

I’m not well versed in PHP but am I right in thinking that when you include a ‘file upload’ in an HTML form and send it to PHP, the key/value pairs are in $_POST and the files are in $_FILES? This is where I am stuck because POSTContent can be created with a byte[] or with a dictionary of key/value pairs. Is there any way on the Gadgeteer side to get this to work? Is it a matter of going really low level and creating the HTTP header manually and opening a file stream etc?

Thanks for your time and your responses so far.