@inrupt/solid-client / resource/file

Module: resource/file

Table of contents

Type aliases

Functions

Type aliases

GetFileOptions

Ƭ GetFileOptions: object

Options when fetching a file from a Pod.

Available options:

  • fetch: A custom fetch function with the same signature as window.fetch. This will be used to execute the actual requests. This option can be used to, for example, attach credentials to requests that need authentication.

Type declaration:

Name

Type

fetch

typeof window.fetch

Defined in: src/resource/file.ts:49


WriteFileOptions

Ƭ WriteFileOptions: GetFileOptions & { contentType: string }

Note

This function is still experimental and subject to change, even in a non-major release.

Options available when writing a file.

Defined in: src/resource/file.ts:231

Functions

deleteFile

deleteFile(file: Url | UrlString | WithResourceInfo, options?: Partial<GetFileOptions>): Promise<void>

Note

This function is still experimental and subject to change, even in a non-major release.

Deletes a file at a given URL.

Parameters:

Name

Type

Description

file

Url | UrlString | WithResourceInfo

The URL of the file to delete

options

Partial<GetFileOptions>

-

Returns: Promise<void>

Defined in: src/resource/file.ts:113


getFile

getFile(input: Url | UrlString, options?: Partial<GetFileOptions>): Promise<File & WithServerResourceInfo>

Note

This function is still experimental and subject to change, even in a non-major release.

Retrieves a file from a URL and returns the file as a blob.

Parameters:

Name

Type

Description

input

Url | UrlString

-

options

Partial<GetFileOptions>

Fetching options: a custom fetcher and/or headers.

Returns: Promise<File & WithServerResourceInfo>

The file as a blob.

Defined in: src/resource/file.ts:78


overwriteFile

overwriteFile<FileExt>(fileUrl: Url | UrlString, file: FileExt, options?: Partial<WriteFileOptions>): Promise<FileExt & WithResourceInfo>

Note

This function is still experimental and subject to change, even in a non-major release.

Saves a file at a given URL, replacing any previous content.

The Solid server will create any intermediary Containers that do not exist yet, so they do not need to be created in advance. For example, if the target URL is https://example.pod/container/resource and https://example.pod/container/ does not exist yet, it will exist after this function resolves successfully.

If you know the media type of the file you are attempting to write, then you should provide this in the options parameter. For example, if you know your file is a JPEG image, then you should provide the media type image/jpeg. If you don’t know, or don’t provide a media type, a default type of application/octet-stream will be applied (which indicates that the file should be regarded as pure binary data).

Type parameters:

Name

Type

FileExt

Blob | Buffer

Parameters:

Name

Type

Description

fileUrl

Url | UrlString

The URL where the file is saved.

file

FileExt

The file to be written.

options

Partial<WriteFileOptions>

Additional parameters for file creation (e.g. a slug, or media type).

Returns: Promise<FileExt & WithResourceInfo>

Defined in: src/resource/file.ts:267


saveFileInContainer

saveFileInContainer<FileExt>(folderUrl: Url | UrlString, file: FileExt, options?: Partial<SaveFileOptions>): Promise<FileExt & WithResourceInfo>

Note

This function is still experimental and subject to change, even in a non-major release.

Saves a file in a folder associated with the given URL. The final filename may or may not be the given slug.

If you know the media type of the file you are attempting to save, then you should provide this in the options parameter. For example, if you know your file is a JPEG image, then you should provide the media type image/jpeg. If you don’t know, or don’t provide a media type, a default type of application/octet-stream will be applied (which indicates that the file should be regarded as pure binary data).

The Container at the given URL should already exist; if it does not, the returned Promise will be rejected. You can initialise it first using createContainerAt, or directly save the file at the desired location using overwriteFile.

This function is primarily useful if the current user does not have access to change existing files in a Container, but is allowed to add new files; in other words, they have Append, but not Write access to a Container. This is useful in situations where someone wants to allow others to, for example, send notifications to their Pod, but not to view or delete existing notifications. You can pass a suggestion for the new Resource’s name, but the server may decide to give it another name — for example, if a Resource with that name already exists inside the given Container. If the user does have access to write directly to a given location, overwriteFile will do the job just fine, and does not require the parent Container to exist in advance.

Type parameters:

Name

Type

FileExt

Blob | Buffer

Parameters:

Name

Type

Description

folderUrl

Url | UrlString

The URL of the folder where the new file is saved.

file

FileExt

The file to be written.

options

Partial<SaveFileOptions>

Additional parameters for file creation (e.g. a slug).

Returns: Promise<FileExt & WithResourceInfo>

A Promise that resolves to the saved file, if available, or null if the current user does not have Read access to the newly-saved file. It rejects if saving fails.

Defined in: src/resource/file.ts:188