|
List Info
Thread: up/download files via araneida?
|
|
| up/download files via araneida? |

|
2006-09-15 07:21:55 |
I'd like to implement a file storage area for an app I'm
working on, where a
user can upload a small number of files and retrieve them
later.
How would I do this with araneida?
Jonathon McKitrick
--
My other computer is your Windows box.
_______________________________________________
lispweb mailing list
lispweb red-bean.com
http
://www.red-bean.com/mailman/listinfo/lispweb
|
|
| up/download files via araneida? |

|
2006-09-15 15:48:22 |
I you're going to use the filesystem, then write a handler
that takes
a POST body, un-base64s it, turns it into a usb8 array, and
writes it
to a file on disk. Record the filename.
Now, hit the bug with Araneida serving up binary files --
SBCL's
streams aren't always cooperative.
On 15 Sep 2006, at 12:21 AM, Jonathon McKitrick wrote:
>
> I'd like to implement a file storage area for an app
I'm working
> on, where a
> user can upload a small number of files and retrieve
them later.
>
> How would I do this with araneida?
>
> Jonathon McKitrick
> --
> My other computer is your Windows box.
>
> _______________________________________________
> lispweb mailing list
> lispweb red-bean.com
> http
://www.red-bean.com/mailman/listinfo/lispweb
_______________________________________________
lispweb mailing list
lispweb red-bean.com
http
://www.red-bean.com/mailman/listinfo/lispweb
|
|
| up/download files via araneida? |

|
2006-09-15 15:53:46 |
On Fri, Sep 15, 2006 at 08:48:22AM -0700, Richard Newman
wrote:
: I you're going to use the filesystem, then write a
handler that takes
: a POST body, un-base64s it, turns it into a usb8 array,
and writes it
: to a file on disk. Record the filename.
Just to be sure... I just set up a form and an input of type
"file", correct?
: Now, hit the bug with Araneida serving up binary files --
SBCL's
: streams aren't always cooperative.
Rats. Can't I just use the static-file-handler?
Jonathon McKitrick
--
My other computer is your Windows box.
_______________________________________________
lispweb mailing list
lispweb red-bean.com
http
://www.red-bean.com/mailman/listinfo/lispweb
|
|
| up/download files via araneida? |

|
2006-09-15 20:20:40 |
On 15 Sep 2006, at 8:53 AM, Jonathon McKitrick wrote:
> On Fri, Sep 15, 2006 at 08:48:22AM -0700, Richard
Newman wrote:
> : I you're going to use the filesystem, then write a
handler that
> takes
> : a POST body, un-base64s it, turns it into a usb8
array, and
> writes it
> : to a file on disk. Record the filename.
>
> Just to be sure... I just set up a form and an input of
type
> "file", correct?
Yes. You'll get a POST body with multipart stuff, I expect.
I've done
a lot of hacking on Araneida, so it might not work for you.
> : Now, hit the bug with Araneida serving up binary
files -- SBCL's
> : streams aren't always cooperative.
>
> Rats. Can't I just use the static-file-handler?
You can try!
_______________________________________________
lispweb mailing list
lispweb red-bean.com
http
://www.red-bean.com/mailman/listinfo/lispweb
|
|
| up/download files via araneida? |

|
2006-09-15 20:42:57 |
On Fri, Sep 15, 2006 at 01:20:40PM -0700, Richard Newman
wrote:
: >Just to be sure... I just set up a form and an input
of type
: >"file", correct?
:
: Yes. You'll get a POST body with multipart stuff, I
expect. I've done
: a lot of hacking on Araneida, so it might not work for
you.
I found the body with the multipart content. I installed
cl-mime in an effort
to figure out how to separate the parts and convert them
back to a file.
That's where I'm stuck right now - parsing the multipart
stuff. I *think*
cl-mime:parse-mime expects request-unparsed-body as the
string it will
decompose into the mime objects.
: >Rats. Can't I just use the static-file-handler?
:
: You can try!
I'm thinking of storing the files as BLOBs in my db.
Jonathon McKitrick
--
My other computer is your Windows box.
_______________________________________________
lispweb mailing list
lispweb red-bean.com
http
://www.red-bean.com/mailman/listinfo/lispweb
|
|
| up/download files via araneida? |

|
2006-09-15 21:00:18 |
> I found the body with the multipart content. I
installed cl-mime
> in an effort
> to figure out how to separate the parts and convert
them back to a
> file.
> That's where I'm stuck right now - parsing the
multipart stuff. I
> *think*
> cl-mime:parse-mime expects request-unparsed-body as the
string it will
> decompose into the mime objects.
My code...
In the handler:
(multiple-value-bind (data data-properties)
(form-data-param "my-param" (request-body
request))
(with-open-file (s filepath
:element-type '(unsigned-byte 8)
:direction :output
:if-does-not-exist :create
:if-exists :supersede)
;; Terrible, terrible encoding issues occur if we
;; supply the data as a string to WRITE-SEQUENCE.
;; Instead, we (rather wastefully) run through it,
;; turning it into a list of bytes!
;; TODO: I can guarantee there is a better way of
;; doing all this.
(write-sequence
(loop for char across data collecting (char-code
char))
s))
In araneida/daemon.lisp:
Line 80:
(defun parse-form-data-body (body-string content-type)
(let ((boundary
(cdr (assoc "boundary"
(car (last (rfc2388:parse-header
content-
type :value)))
:test #'string=))))
(rfc2388:parse-mime
body-string
boundary
:write-content-to-file nil)))
In araneida/request.lisp:
(defmethod request-body ((r request))
(if (slot-boundp r 'body)
(slot-value r 'body)
(setf (slot-value r 'body)
(let ((body (request-unparsed-body r))
(len (request-unparsed-body-length r)))
(if body
(let ((content-type (car (request-header r
:content-
type))))
(cond ((string= content-type
"application/x-www-
form-urlencode
d")
(parse-form-urlencoded-body
#+lispworks
(map 'string
;; for some reason
lispworks wants
an array of c
ode characters
;; according to Bob
Hutchinson
(hutch at recursi
ve.ca)
;; -- Alan Shields [14
November 2005]
(lambda (c) (code-char c))
body)
#-lispworks
body
'(#\&) len))
((search
"multipart/form-data" content-type)
;; Ruh-roh! Have to parse a
form-data body.
;; This returns something like
;; Have to use a separate accessor
because
this is much
;; richer.
(parse-form-data-body body
content-type))
(t
;; Tell ya what, we'll just
return the raw
contents.
body)))
nil)))))
Should do the trick. A recent araneida might have those
patches already.
-R
_______________________________________________
lispweb mailing list
lispweb red-bean.com
http
://www.red-bean.com/mailman/listinfo/lispweb
|
|
| up/download files via araneida? |

|
2006-09-16 02:10:03 |
On Fri, Sep 15, 2006 at 02:00:18PM -0700, Richard Newman
wrote:
: (parse-form-urlencoded-body
Is this one of your local modifications I need to get?
Jonathon McKitrick
--
My other computer is your Windows box.
_______________________________________________
lispweb mailing list
lispweb red-bean.com
http
://www.red-bean.com/mailman/listinfo/lispweb
|
|
[1-7]
|
|
|
about | contact Other archives ( Real Estate discussion Medical topics )
|