Options
All
  • Public
  • Public/Protected
  • All
Menu

Class FileManager

FileManager is primarily used to manage a file. Using the BucketManager.file method, you can create a FileManager instance for a specific file identified by its unique name or id.

export

Hierarchy

Index

Constructors

  • new FileManager(bucketNameOfId: string, fileNameOrId: string, fetcher: Fetcher): FileManager
  • Creates an instance of FileManager to manage a specific bucket of your cloud storage.

    Parameters

    • bucketNameOfId: string

      The name or id of the bucket that this file is contained in

    • fileNameOrId: string

      The name of id of the file that this file manager will be operating on

    • fetcher: Fetcher

      The http client to make RESTful API calls to the application's execution engine

    Returns FileManager

Properties

#bucketNameOrId: string

The name or id of the bucket

#fileNameOrId: string

The name or id of the file

fetcher: Fetcher

The http client to make RESTful API calls to the application's execution engine

Methods

  • addTags(tags: string | string[]): Promise<{ data: null | object; errors: null | APIError }>
  • Adds the specified tags to file's metadata.

    If the client library key is set to enforce session, an active user session is required (e.g., user needs to be logged in) to call this method.

    Parameters

    • tags: string | string[]

      A single tag or an array of tags to add to file's metadata

    Returns Promise<{ data: null | object; errors: null | APIError }>

    Returns the updated file information

  • copyTo(bucketNameOrId: string): Promise<{ data: null | object; errors: null | APIError }>
  • Copies the file to another bucket. If there already exists a file with the same name in destination bucket, it ensures the copied file name to be unique in its new destination.

    If the client library key is set to enforce session, an active user session is required (e.g., user needs to be logged in) to call this method.

    Parameters

    • bucketNameOrId: string

      The name or id of the bucket to copy the file into.

    Returns Promise<{ data: null | object; errors: null | APIError }>

    Returns the copied file information

  • delete(): Promise<{ errors: null | APIError }>
  • Deletes the file from the bucket.

    If the client library key is set to enforce session, an active user session is required (e.g., user needs to be logged in) to call this method.

    Returns Promise<{ errors: null | APIError }>

  • download(): Promise<{ data: null | Blob; errors: null | APIError }>
  • Downloads the file.

    If the client library key is set to enforce session, an active user session is required (e.g., user needs to be logged in) to call this method.

    Returns Promise<{ data: null | Blob; errors: null | APIError }>

    Returns the contents of the file in a Blob

  • duplicate(duplicateName?: string): Promise<{ data: null | object; errors: null | APIError }>
  • Duplicates an existing file within the same bucket.

    If the client library key is set to enforce session, an active user session is required (e.g., user needs to be logged in) to call this method.

    Parameters

    • Optional duplicateName: string

      The new duplicate file name. If not specified, uses the fileName as template and ensures the duplicated file name to be unique in its bucket.

    Returns Promise<{ data: null | object; errors: null | APIError }>

    Returns the new duplicate file information

  • exists(): Promise<{ data: null | boolean; errors: null | APIError }>
  • Check if the file exists. It returns false if file does not exist.

    If the client library key is set to enforce session, an active user session is required (e.g., user needs to be logged in) to call this method.

    Returns Promise<{ data: null | boolean; errors: null | APIError }>

    Returns true if file exists, false otherwise

  • getInfo(): Promise<{ data: null | object; errors: null | APIError }>
  • Gets information about the file.

    If the client library key is set to enforce session, an active user session is required (e.g., user needs to be logged in) to call this method.

    Returns Promise<{ data: null | object; errors: null | APIError }>

    Returns basic file metadata informaton.

  • makePrivate(): Promise<{ data: null | object; errors: null | APIError }>
  • Sets the default privacy of the file to false.

    If the client library key is set to enforce session, an active user session is required (e.g., user needs to be logged in) to call this method.

    Returns Promise<{ data: null | object; errors: null | APIError }>

    Returns the updated file information

  • makePublic(): Promise<{ data: null | object; errors: null | APIError }>
  • Sets the default privacy of the file to true.

    If the client library key is set to enforce session, an active user session is required (e.g., user needs to be logged in) to call this method.

    Returns Promise<{ data: null | object; errors: null | APIError }>

    Returns the updated file information

  • moveTo(bucketNameOrId: string): Promise<{ data: null | object; errors: null | APIError }>
  • Moves the file to another bucket. The file will be removed from its current bucket and will be moved to its new bucket. If there already exists a file with the same name in destination bucket, it ensures the moved file name to be unique in its new destination.

    If the client library key is set to enforce session, an active user session is required (e.g., user needs to be logged in) to call this method.

    Parameters

    • bucketNameOrId: string

      The name or id of the bucket to move the file into.

    Returns Promise<{ data: null | object; errors: null | APIError }>

    Returns the moved file information

  • removeTags(tags: string | string[]): Promise<{ data: null | object; errors: null | APIError }>
  • Removes the specified tags from file's metadata.

    If the client library key is set to enforce session, an active user session is required (e.g., user needs to be logged in) to call this method.

    Parameters

    • tags: string | string[]

      A single tag or an array of tags to remove from file's metadata

    Returns Promise<{ data: null | object; errors: null | APIError }>

    Returns the updated file information

  • rename(newName: string): Promise<{ data: null | object; errors: null | APIError }>
  • Renames the file.

    If the client library key is set to enforce session, an active user session is required (e.g., user needs to be logged in) to call this method.

    Parameters

    • newName: string

      The new name of the file.

    Returns Promise<{ data: null | object; errors: null | APIError }>

    Returns the updated file information

  • Replaces an existing file with another. It keeps the name of the file but replaces file contents, size, encoding and mime-type with the newly uploaded file info.

    If onProgress callback function is defined in FileUploadOptions, it periodically calls this function to inform about upload progress. Please note that for the moment onProgress callback function can only be used in clients where XMLHttpRequest object is available (e.g., browsers).

    If the client library key is set to enforce session, an active user session is required (e.g., user needs to be logged in) to call this method.

    Parameters

    • fileBody: any

      The body of the new file that will be used to replace the existing file

    • options: FileUploadOptions

      Content type and privacy setting of the new file. contentType is ignored, if fileBody is Blob, File or FormData, otherwise contentType option needs to be specified. If not specified, contentType will default to text/plain;charset=UTF-8. If isPublic is not specified, defaults to the bucket's privacy setting.

    Returns Promise<{ data: null | object; errors: null | APIError }>

    Returns the metadata of the file after replacement

  • updateInfo(newName: string, isPublic: boolean, tags: string | string[]): Promise<{ data: null | object; errors: null | APIError }>
  • Updates the overall file metadata (name, isPublic and tags) in a single method call.

    If the client library key is set to enforce session, an active user session is required (e.g., user needs to be logged in) to call this method.

    Parameters

    • newName: string

      The new name of the file.

    • isPublic: boolean

      The privacy setting of the file.

    • tags: string | string[]

      Array of string values that will be added to the file metadata.

    Returns Promise<{ data: null | object; errors: null | APIError }>

    Returns the updated file information

Generated using TypeDoc