Squeak
  links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
Recipe: Saving a file to your computer from the Internet
Last updated at 4:45 pm UTC on 16 January 2006
The Problem:
You want to make a button that automaticaly goes out to the web, collects some files, and saves them into a local directory for you to access later. This is useful when putting together a tutorial for novice users (or anyone who would prefer not to need to go out and collect the files themselves!). All the source files that will be used are copied to the user's disk automaticaly.

The Solution:

"make a subdirectory to put them in (if it doesn't exist already)"
(FileDirectory default directoryExists: 'video')
ifFalse:
[FileDirectory default createDirectory: 'video'.].

"get the document"
mimeDoc := HTTPClient httpGetDocument: 'http://coweb.cc.gatech.edu:8888/uploads/squeakers/14/ice_age_bgsubtract_1.mpg'.

"save it"
fileName := 'video',(FileDirectory pathNameDelimiter) asString, 'test1.mpg'.
file := FileStream fileNamed: fileName.
file reset.
file binary.
file nextPutAll: mimeDoc content.
file close.