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 10:12 am UTC on 16 March 2019
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')
		[FileDirectory default createDirectory: 'video'.].

"get the document since April 2015 [1]"
       doc := WebClient httpGet: '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: doc content.
	file close.

[1] 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'.