@inrupt/solid-client / resource/file

# Module: resource/file¶

## 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, options?): 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

The URL of the file to delete

options

Partial<GetFileOptions>

-

#### Returns¶

Promise<void>

#### Defined in¶

src/resource/file.ts:113

### getFile¶

getFile(input, options?): 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

-

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, file, options?): 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

FileExt: Blob | Buffer

#### Parameters¶

Name

Type

Description

fileUrl

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, file, options?): 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.

#### Type parameters¶

Name

Type

FileExt

FileExt: Blob | Buffer

#### Parameters¶

Name

Type

Description

folderUrl

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