Shop OBEX P1 Docs P2 Docs Learn Events
Is there some code for sending files via http? — Parallax Forums

Is there some code for sending files via http?

Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
edited 2011-01-29 15:42 in Accessories
I'd like to upload files to the spinneret via the browser.

Is there code somewhere already for this?

Thanks
OBC

Comments

  • wiresalotwiresalot Posts: 40
    edited 2011-01-29 13:07
    None that I know of. Whats wrong with using FTP (file transfer protocol)

    wiresalot
  • Mike GMike G Posts: 2,702
    edited 2011-01-29 13:41
    FTP is great but as far as I know we don't have the software for the SPinneret. Plus there might be programming memory constraints trying to run both HTTP and FTP on the Spinneret.

    I'm working on HTTP file upload but it has been more difficult than I expected.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-01-29 14:36
    If anyone has gotten POST to work, uploading a file should also work, since the file contents will be one of the parameters. But it will be encoded base64, so you will have to decode it back to binary/ASCII.

    -Phil
  • Beau SchwabeBeau Schwabe Posts: 6,566
    edited 2011-01-29 14:38
    OBC,

    Something like this?
            <form action='File Upload' method=post enctype='multipart/form-data'>
            <label accesskey=u>Select a document from your computer:
            <input type=file name=file accept='text/html'></label>
            <label accesskey=V><input type=submit value='Upload it!'></label>
            </form>
    

    See the code HERE in action <-The content length should be under 2K

    If you DEBUG through the PST with something like...
             PST.str(@data)
    

    ... after you have established a connection and sent a file, you should see the data content on the Spinneret side. Something like this ...
    Content-Type: multipart/form-data; boundary=---------------------------669407381956690083388292077
    
    Content-Length: 246
    
    
    
    -----------------------------669407381956690083388292077
    
    Content-Disposition: form-data; name="file"; filename="This is a test"
    
    Content-Type: application/octet-stream
    
    
    
    Hello World
    
    
    -----------------------------669407381956690083388292077--
    


    In this case the file was a text file named "This is a Test" ... inside the file it contained "Hello World"
  • Mike GMike G Posts: 2,702
    edited 2011-01-29 15:21
    I messed up on the content-type... Thanks.
  • Mike GMike G Posts: 2,702
    edited 2011-01-29 15:42
    Okay, now I'm kicking myself. I messed with the HTTP file upload for a few hours then gave up because I was not seeing what I expected in the HTTP request. Well, I had a simple HTML fart... geez

    Thanks Phil and Beau for setting me straight.
Sign In or Register to comment.