Skip to main content
Skip to main content
You're viewing the documentation for v1, which isn't the latest Medusa version.Latest documentation

IFileModuleService

The main service interface for the File Module.

Methods

create

**create**(data, sharedContext?): Promise<[FileDTO](types.FileTypes.FileDTO.mdx)[]>

This method uploads files to the designated file storage system.

Example

const [file] = await fileModuleService.create([{
filename: "product.png",
mimeType: "image/png",
content: "somecontent"
}])

Parameters

dataCreateFileDTO[]Required
The files to be created.
sharedContextContext
A context used to share resources, such as transaction manager, between the application and the module.

Returns

PromisePromise<FileDTO[]>Required
The created files.

**create**(data, sharedContext?): Promise&#60;[FileDTO](types.FileTypes.FileDTO.mdx)&#62;

This method uploads a file to the designated file storage system.

Example

const file = await fileModuleService.create({
filename: "product.png",
mimeType: "image/png",
content: "somecontent"
})

Parameters

dataCreateFileDTORequired
The file to be created.
sharedContextContext
A context used to share resources, such as transaction manager, between the application and the module.

Returns

PromisePromise<FileDTO>Required
The created file.

delete

**delete**(ids, sharedContext?): Promise&#60;void&#62;

This method deletes files by their IDs.

Example

await fileModuleService.delete(["file_123"])

Parameters

idsstring[]Required
The IDs of the files.
sharedContextContext
A context used to share resources, such as transaction manager, between the application and the module.

Returns

PromisePromise<void>Required
Resolves when the files are deleted successfully.

**delete**(id, sharedContext?): Promise&#60;void&#62;

This method deletes a file by its ID.

Example

await fileModuleService.delete("file_123")

Parameters

idstringRequired
The ID of the file.
sharedContextContext
A context used to share resources, such as transaction manager, between the application and the module.

Returns

PromisePromise<void>Required
Resolves when the file is deleted successfully.

retrieve

This method retrieves a file with a downloadable URL by its ID.

Example

const file = await fileModuleService.retrieve("file_123")

Parameters

idstringRequired
The ID of the file.
The configurations determining how the file is retrieved. Its properties, such as select or relations, accept the attributes or relations associated with a file.
sharedContextContext
A context used to share resources, such as transaction manager, between the application and the module.

Returns

PromisePromise<FileDTO>Required
The retrieved file.

list

This method is used to retrieve a file by ID, similarly to retrieve. Enumeration of files is not supported, but the list method is in order to support remote queries

Parameters

The filters to apply on the retrieved files.
The configurations determining how the files are retrieved. Its properties, such as select or relations, accept the attributes or relations associated with a file.
sharedContextContext
A context used to share resources, such as transaction manager, between the application and the module.

Returns

PromisePromise<FileDTO[]>Required
The list of files. In this particular case, it will either be at most one file.

listAndCount

This method is used to retrieve a file by ID, similarly to retrieve. Enumeration of files is not supported, but the listAndCount method is in order to support remote queries

Parameters

The filters to apply on the retrieved files.
The configurations determining how the files are retrieved. Its properties, such as select or relations, accept the attributes or relations associated with a file.
sharedContextContext
A context used to share resources, such as transaction manager, between the application and the module.

Returns

PromisePromise<[FileDTO[], number]>Required
The list of files and their count. In this particular case, it will either be at most one file.
Was this section helpful?