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:09 pm UTC on 1 January 2016
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"
	doc := HTTPClient httpGetDocument: 'http://coweb.cc.gatech.edu:8888/uploads/squeakers/14/ice_age_bgsubtract_1.mpg'.
or since April 2015
       doc := WebClient httpGet: 'http://wiki.squeak.org/squeak/2275'.

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