These four methods allow you to store files in your persitent storage.
Files that are on your agent's disk but not saved to your persistent storage will be lost when your agent exits.
Before these methods can be used, you need to :ref:`require() and create() the agent module <agent-module>`.
buster.save(urlOrPath [, saveAs, headers, callback])
Saves a distant or local file to your persistent storage.
This method is asynchronous and returns nothing. Use the callback to know when it has finished.
urlOrPath(String)URL or path of the file to be saved.
https://www.google.com/images/srpr/logo11w.png(from the web)foo/my_screenshot.jpg(from your agent's disk)http://soundcloud.com/(you'll get the HTML content of their homepage)
When saving a distant file, the MIME type is taken from the
Content-TypeHTTP header (if present). When saving a local file, the MIME type is guessed from the file extension (if this fails, no MIME type is set).saveAs(String)Where to put the file on your persistent storage (optional). By default, the name will be taken from
urlOrPathand the file will be saved at the root of your agent's folder in your persistent storage. If a file with the same name already exists, it is overwritten.foo/(saveshttp://example.com/baz/bar.pngasfoo/bar.png)- null (saves
http://example.com/foo/bar.pngasbar.png) foo/(fails onhttp://example.com/withcould not determine filename)foo/a(saveshttp://example.com/bar.pngasfoo/a)
You do not need to create any intermediate directory (
a/b/c/d/e.jpgwill work).headers(PlainObject)- HTTP headers to use when requesting the file (optional). Cookies are automatically set when using CasperJS or PhantomJS.
callback(Function(String err, String url))- Function to call when finished. When there is no error,
erris null andurlcontains the full URL to the file on your persistent storage.
buster.saveBase64(base64String, saveAs [, mime, callback])
Saves a Base64 encoded file to your persistent storage.
This method is asynchronous and returns nothing. Use the callback to know when it has finished.
base64String(String)- Contents of the file to save. Can be pure Base64 or a Data URI Scheme string starting with
data:. saveAs(String)Where to put the file on your persistent storage. If a file with the same name already exists, it is overwritten.
file.jpgany/sub/directory/file.pngdir/(fails because no file name was given)
You do not need to create any intermediate directory (
a/b/c/dwill work).mime(String)MIME type of the file being saved (optional). By default it is guessed either from the Data URI Scheme string or from the file extension of the
saveAsparameter (if this fails, no MIME type is set).image/jpegimage/pngimage/svg+xml
callback(Function(String err, String url))- Function to call when finished (optional). When there is no error,
erris null andurlcontains the full URL to the file in your persistent storage.
buster.saveFolder([path, saveAs, callback])
Saves a folder from your agent's disk to your persistent storage.
This method is asynchronous and returns nothing. Use the callback to know when it has finished.
path(String)Path of the folder to save (optional, defaults to
.)..(everything from your current working directory)any/sub/../sub/directory
Each file has its MIME type guessed from its extension (if this fails, no MIME type is set).
saveAs(String)Where to put the folder on your persistent storage (optional). By default, the folder will be saved at the root of your agent's folder in your persistent storage. If files with the same name already exist, they are overwritten.
/or empty string (root of your agent's folder in your persistent storage)any/sub/directorydir/foo.txt(this will create a directory namedfoo.txt, obviously not recommended)
You do not need to create any intermediate directory (
a/b/c/dwill work).callback(Function(String err, String url))- Function to call when finished (optional). When there is no error,
erris null andurlcontains the full URL to the folder in your persistent storage.
buster.saveText(text, saveAs [, mime, callback])
Saves a string to a file in your persistent storage.
This method is asynchronous and returns nothing. Use the callback to know when it has finished.
text(String)- Contents of the file to save. Can be anything, really.
saveAs(String)Where to put the file on your persistent storage. If a file with the same name already exists, it is overwritten.
file.txtany/sub/directory/file.jsondir/(fails because no file name was given)
You do not need to create any intermediate directory (
a/b/c/dwill work).mime(String)MIME type of the file being saved (optional). By default it is guessed from the file extension of the
saveAsparameter (if this fails, no MIME type is set).application/jsontext/csvtext/html
callback(Function(String err, String url))- Function to call when finished (optional). When there is no error,
erris null andurlcontains the full URL to the file in your persistent storage.