Pages: [1]   Go Down
Author Topic: upload picture using web server to sd card.  (Read 1543 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 1
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hello, i am using a arduino. to created a web server, so far so good. but when i want to create a new function that can upload the picture in my computer to the sd card that located in the arduina, i found out that there is no example and there is no any code that can copy a picture. can anyone help me???

thank u.
Logged

Holland
Offline Offline
Newbie
*
Karma: 2
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Look for tinywebserver, it has an upload fuction.
It's based on the HTML command 'PUT'.
Altough PUT is a normal HTTP command, I found out that most webbrowser convert PUT into GET.
To bypass this, u can use Javasript, something like:

Code:
<script type="text/javascript">
    // Create the communications object.
    var xmlhttp;
    if (window.XMLHttpRequest) {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else {
        // code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
   
    // Set up the request to send data to the server.
    // Make it synchronous, so we know how page rendering should proceed
    async = false;
    resource = "http://192.168.your webaddress";
    data = "your file";
   
    xmlhttp.open("PUT", resource, async);   
    xmlhttp.send(data);
 </script>

If you find tinywebserver to complicated, you can also use Ladyada's sketch: http://www.ladyada.net/learn/arduino/ethfiles.html, which is also often found on this forum.
In her sketch, you look for the GET command, but you can easily add a routine which looks for PUT.
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hallo hong, how about the arduino code?
do you mean that i can use myFile.println("pic in text");
to write my pic to the sd card?
Logged

Holland
Offline Offline
Newbie
*
Karma: 2
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, it's more or less the same as reading from the SDcard and write it to a webbrowser.
In this (opposite) case, you create a loop and write bytes to the SDcard while there are bytes available.
Instead of println you use print, because you write a stream of bytes and you don't want any cr/nl inserted.
When I've time, I'll look for and post an example.
Logged

Pages: [1]   Go Up
Jump to: