FileRef

FileRef

This class represents a local file. It is typically used by an SDK Operation which accepts or returns files.

When a FileRef instance is created by this SDK while referring to a temporary file location, calling any of the methods to save the fileRef (For example, FileRef#writeToStream, FileRef#saveAsFile etc.) will delete the temporary file.

Members

mediaType

Returns the media type of the file-ref object FileRef.

Methods

(static) createFromLocalFile(filePathnon-null, mediaTypeopt) → {FileRef}

Creates a FileRef instance from a local file path. If no media type is provided, it will be inferred from the file extension.

Parameters:
Name Type Attributes Description
filePath string

Local file path, either absolute path or relative to the working directory.

mediaType string <optional>

Media type to identify the local file format.

Returns:

A FileRef instance.

Type
FileRef

(static) createFromStream(inputStreamnon-null, mediaTypenon-null) → {FileRef}

Creates a FileRef instance from a readable stream using the specified media type.

The stream is not read by this method but by consumers of file content i.e. the execute method of an operation such as CreatePDFOperation#execute .

Parameters:
Name Type Description
inputStream stream.Readable

Readable Stream representing the file.

mediaType string

Media type to identify the file format.

Returns:

A FileRef instance.

Type
FileRef

saveAsFile(destinationFilePathnon-null) → {Promise.<void>}

Saves this file to the location specified by destinationFilePath. If this FileRef instance refers to a temporary local file created by the SDK, that temporary file is deleted.

The directories mentioned in the specified argument are created if they do not exist.

Parameters:
Name Type Description
destinationFilePath string

Local file path, either an absolute path or relative to the working directory.

Throws:
  • If the file already exists.

    Type
    Error
  • If this FileRef instance does not represent an operation result.

    Type
    Error
Returns:

A Promise that resolves when the fileRef instance has been moved to the specified location.

Type
Promise.<void>

writeToStream(writableStreamnon-null)

Writes the contents of this file to writableStream. If this FileRef instance refers to a temporary local file created by the SDK, that temporary file is deleted.
Note: This method does not close the writableStream.

Parameters:
Name Type Description
writableStream stream.Writable

The destination writable stream.

Throws:

If this FileRef instance does not represent an operation result.

Type
Error

(static) createFromURL(urlnon-null) → {FileRef}

Creates a FileRef instance from the input URL. As of now, this method is only supported for creation of PDF from HTML using CreatePDFOperation.

Parameters:
Name Type Description
url string

Input URL.

Returns:

A FileRef instance.

Type
FileRef