Recipe: Saving a file to your computer from the Internet
Last updated at 10:12 am UTC on 16 March 2019
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.
"make a subdirectory to put them in (if it doesn't exist already)"
(FileDirectory default directoryExists: 'video')
[FileDirectory default createDirectory: 'video'.].
"get the document since April 2015 "
doc := WebClient httpGet: 'http://coweb.cc.gatech.edu:8888/uploads/squeakers/14/ice_age_bgsubtract_1.mpg'.
fileName := 'video',(FileDirectory pathNameDelimiter) asString, 'test1.mpg'.
file := FileStream fileNamed: fileName.
file nextPutAll: doc content.
 The use of HTTPClient is no longer recommended.
doc := HTTPClient httpGetDocument: 'http://coweb.cc.gatech.edu:8888/uploads/squeakers/14/ice_age_bgsubtract_1.mpg'.