Binary.upload(source, options)

Prepares binary data locally for uploading to Scrivito.

By default, the type property of the passed-in source is used as the content type but can be overridden using options. If source is a Blob, be sure to specify a filename in the options. For File objects, the filename falls back to “File#file”.

Note: This method does not perform the actual upload but returns a FutureBinary. The actual upload can be triggered by putting the FutureBinary into an Obj.

Params

  • source (Blob or File) - Local data that can be uploaded to a Binary
  • options (optional) (Object) - Options to pass when uploading a Binary
    • filename (String) - The file name to use for the new Binary; mandatory for blobs.
    • contentType (String) - A content type for overriding the type of the source.

Throws

  • ArgumentError - If the source is neither a Blob nor a File.
  • ArgumentError - If any of the passed-in options are blank.
  • ArgumentError - If source is a “Blob” and no filename is given.

Returns

FutureBinary

Examples

Running the following code in the console creates an image object from SVG markup. You should be able to see this image in the Content Browser.

The following example uploads an image file a user has selected using the file input element whose ID is “upload”. The uploaded file is put into an new image object:

In line three of the example above, the file is uploaded with a filename and content type determined by the browser. You can specify a custom filename and content type when uploading: