[racket] Web server and file upload/download examples

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Mon Oct 8 15:18:09 EDT 2012

Danny's right on all counts. I don't think there's Racket client
support for multipart/form-data.

If you know you're communicating with your own server, you can also
just send the file data as the post data (request-post-data/raw req)
and the filename (if you need it) as a GET query arg.

Jay

On Mon, Oct 8, 2012 at 11:31 AM, Danny Yoo <dyoo at hashcollision.org> wrote:
> On Mon, Oct 8, 2012 at 4:56 AM, Erich Rast <erich at snafu.de> wrote:
>> Hi,
>>
>> I'm not very experienced with using the web server yet and am looking
>> for advice and examples of how to download and upload files. I'm
>> particularly interested in any example of uploading a file using a
>> racket client (not a browser) to the web server, because it seems hard
>> to understand this from just the docs alone.
>
> On the server side of things, I believe we can use bindings-assq on an
> HTTP request's collection of name-value binding pairs.  The value we
> get back from bindings-assq can be a binding:file structure.
>
> Mirroring the example from
> http://docs.racket-lang.org/web-server/http.html#(def._((lib._web-server/http/request-structs..rkt)._request-bindings/raw)),
> an example that expects file input would look something like this:
>
> ;;;;;;;;;;;;;;;;;;;;;;
> (require web-server/http)
>
> ;; print-file-content: request -> void
> (define (print-file-content req)
>   (match (bindings-assq #"file" (request-bindings/raw req))
>     [(struct binding:file (id filename headers content))
>      (printf "I got a file with content: ~s\n" content)]))
> ;;;;;;;;;;;;;;;;;;;;;;
>
>
> On the client side of things, it looks like we want to send a
> "multipart/form-data" encoding of the file's bytes over as the body of
> a post-pure-port.
>
> The details on how to build this thing should already be handled by a
> library...  However, I'm a little disconcerted: I can't seem to find a
> Racket library on PLaneT or the standard library that handles this
> task.  Basically, I'm looking for the counterpart of the net/uri-codec
> functions, but for encoding to the mulitpart/form-data format.  I must
> be missing something?
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users



-- 
Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University
http://faculty.cs.byu.edu/~jay

"The glory of God is Intelligence" - D&C 93

Posted on the users mailing list.