[drakma-devel] Drakma : Problem saving file
lam at tuxfamily.org
lam at tuxfamily.org
Wed Dec 6 08:47:17 UTC 2006
hello,
i make some test with drakma and i have a problem with http-request :
CL-USER> (with-open-file (os (format nil "/tmp/~A.png" "tttt")
:direction :output
:if-exists :supersede
:element-type 'unsigned-byte)
(multiple-value-bind (body-stream status-code headers uri
stream must-close)
(drakma:http-request
"http://stats-dev/cgi-bin/view_image.cgi?filename=/tmp/sms_5Avkjm.png"
:want-stream t :force-binary t :content-length t)
(declare (ignore headers uri stream must-close))
(when (= status-code 200)
(format t "Type ~A~%" (type-of body-stream))
(loop for c = (read-byte body-stream nil)
until (null c)
do (progn
(format t "Write ~%")
(write-byte c os)))
(close body-stream))))
Type FLEXI-IO-STREAM
T
after i try with another image :
CL-USER> (with-open-file (os (format nil "/tmp/~A.png" "tttt")
:direction :output
:if-exists :supersede
:element-type 'unsigned-byte)
(multiple-value-bind (body-stream status-code headers uri
stream must-close)
(drakma:http-request
"http://www.google.com/images/logo_sm.gif"
:want-stream t :force-binary t :content-length t)
(declare (ignore headers uri stream must-close))
(when (= status-code 200)
(format t "Type ~A~%" (type-of body-stream))
(loop for c = (read-byte body-stream nil)
until (null c)
do (progn
(format t "Write ~%")
(write-byte c os)))
(close body-stream))))
Type FLEXI-IO-STREAM
Write
Write
Write
Write
Write
Write
[...]
Write
Write
T
and the file /tmp/tttt.png contains the google's logo. With the first
request, the file is empty.
Here it is the differents between the 2 requests :
CL-USER> (drakma:http-request
"http://stats-dev/cgi-bin/view_image.cgi?filename=/tmp/sms_5Avkjm.png"
:want-stream t)
#<FLEXI-STREAMS:FLEXI-IO-STREAM {B0F1BF9}>
200
((:DATE . "Tue, 05 Dec 2006 18:09:17 GMT")
(:SERVER
. "Apache/1.3.34 (Debian) PHP/4.4.4-6 mod_jk/1.2.18 mod_ssl/2.8.25
OpenSSL/0.9.8c mod_perl/1.29")
(:CONNECTION . "close") (:TRANSFER-ENCODING . "chunked")
(:CONTENT-TYPE . "image/png"))
#<URI
http://stats-dev/cgi-bin/view_image.cgi?filename=/tmp/sms_5Avkjm.png>
#<FLEXI-STREAMS:FLEXI-IO-STREAM {B0F1BF9}>
T
and :
CL-USER> (drakma:http-request
"http://www.google.com/images/logo_sm.gif"
:want-stream t)
#<FLEXI-STREAMS:FLEXI-IO-STREAM {B13C631}>
200
((:CONTENT-TYPE . "image/gif")
(:LAST-MODIFIED . "Wed, 07 Jun 2006 19:38:24 GMT")
(:EXPIRES . "Sun, 17 Jan 2038 19:14:07 GMT") (:SERVER . "GWS/2.1")
(:CONTENT-LENGTH . "4707") (:DATE . "Tue, 05 Dec 2006 18:10:07 GMT"))
#<URI http://www.google.com/images/logo_sm.gif>
#<FLEXI-STREAMS:FLEXI-IO-STREAM {B13C631}>
T
i see that in the request which have a problem content-length is not
sended.
but i don't really understand why the first image is empty.
thanks if someone understand my problem.
More information about the Drakma-devel
mailing list