[squeak-dev] Re: Download PDF using WebClient
Andreas Raab
andreas.raab at gmx.de
Mon Oct 25 21:41:43 UTC 2010
On 10/25/2010 2:20 PM, Bernhard Pieber wrote:
> Dear Squeakers,
>
> I have a problem downloading a PDF file using WebClient. I use the following code:
>
> | client resp file |
> client := WebClient new.
> [resp := client httpGet: 'http://dl.dropbox.com/u/6204244/mcs-ftl.pdf'.
> resp isSuccess ifFalse:[^self error: resp status].
> "Stream the content from the response"
> file := FileStream newFileNamed: 'mcs-ftl.pdf'.
> resp streamTo: file size: resp contentLength progress: nil.
> file close] ensure: [client close]
>
> I took the code from the WebClient Responses help page and only slightly modified it.
>
> The problem is that I can open the file with Preview but all the pages are blank. The downloaded file has 9.9 MB while the original has 7.2 MB. So clearly something went wrong. Maybe some problem with the encoding?
>
> Any idea how to fix that? I'd be most thankful.
Make the file #binary before downloading. Otherwise you'll end up with
crlf, utf8 and whatnot conversions.
Cheers,
- Andreas
More information about the Squeak-dev
mailing list
|