feat: Add support for uploading a file directly to the file provider from the client (#12224)
* feat: Add support for uploading a file directly to the file provider from the client * fix: Add missing types and add a couple of module tests * fix: Allow nested routes, add test for it
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
/**
|
||||
* The access level of the file.
|
||||
*/
|
||||
export type FileAccessPermission = "public" | "private"
|
||||
|
||||
/**
|
||||
* The File details.
|
||||
*/
|
||||
@@ -24,3 +29,14 @@ export interface FilterableFileProps {
|
||||
*/
|
||||
id?: string
|
||||
}
|
||||
|
||||
export interface UploadFileUrlDTO {
|
||||
/**
|
||||
* The URL of the file.
|
||||
*/
|
||||
url: string
|
||||
/**
|
||||
* The key of the file.
|
||||
*/
|
||||
key: string
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { FileAccessPermission } from "./common"
|
||||
|
||||
/**
|
||||
* The File to be created.
|
||||
*/
|
||||
@@ -9,7 +11,7 @@ export interface CreateFileDTO {
|
||||
|
||||
/**
|
||||
* The mimetype of the uploaded file
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* image/png
|
||||
*/
|
||||
@@ -23,5 +25,22 @@ export interface CreateFileDTO {
|
||||
/**
|
||||
* The access level of the file. Defaults to private if not passed
|
||||
*/
|
||||
access?: "public" | "private"
|
||||
access?: FileAccessPermission
|
||||
}
|
||||
|
||||
export interface GetUploadFileUrlDTO {
|
||||
/**
|
||||
* The name of the file to be uploaded
|
||||
*/
|
||||
filename: string
|
||||
|
||||
/**
|
||||
* The mimetype of the file to be uploaded
|
||||
*/
|
||||
mimeType?: string
|
||||
|
||||
/**
|
||||
* The access level of the file to be uploaded. Defaults to private if not passed
|
||||
*/
|
||||
access?: FileAccessPermission
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { FileAccessPermission } from "./common"
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*
|
||||
@@ -71,7 +73,34 @@ export type ProviderUploadFileDTO = {
|
||||
/**
|
||||
* The access level of the file. Defaults to private if not passed
|
||||
*/
|
||||
access?: "public" | "private"
|
||||
access?: FileAccessPermission
|
||||
}
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*
|
||||
* The details of the file to get a presigned upload URL for.
|
||||
*/
|
||||
export type ProviderGetPresignedUploadUrlDTO = {
|
||||
/**
|
||||
* The filename of the file to get a presigned upload URL for.
|
||||
*/
|
||||
filename: string
|
||||
|
||||
/**
|
||||
* The mimetype of the file to get a presigned upload URL for.
|
||||
*/
|
||||
mimeType?: string
|
||||
|
||||
/**
|
||||
* The access level of the file to get a presigned upload URL for.
|
||||
*/
|
||||
access?: FileAccessPermission
|
||||
|
||||
/**
|
||||
* The validity of the presigned upload URL in seconds.
|
||||
*/
|
||||
expiresIn?: number
|
||||
}
|
||||
|
||||
export interface IFileProvider {
|
||||
@@ -103,4 +132,16 @@ export interface IFileProvider {
|
||||
*
|
||||
*/
|
||||
getPresignedDownloadUrl(fileData: ProviderGetFileDTO): Promise<string>
|
||||
|
||||
/**
|
||||
* This method is used to get a presigned upload URL for a file.
|
||||
* If the file provider does not support direct upload, an exception will be thrown when calling this method.
|
||||
*
|
||||
* @param {ProviderGetPresignedUploadUrlDTO} fileData - The details of the file to get a presigned upload URL for.
|
||||
* @returns {Promise<ProviderFileResultDTO>} The presigned URL and file key to upload the file to
|
||||
*
|
||||
*/
|
||||
getPresignedUploadUrl?(
|
||||
fileData: ProviderGetPresignedUploadUrlDTO
|
||||
): Promise<ProviderFileResultDTO>
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { IModuleService } from "../modules-sdk"
|
||||
import { FileDTO, FilterableFileProps } from "./common"
|
||||
import { FileDTO, FilterableFileProps, UploadFileUrlDTO } from "./common"
|
||||
import { FindConfig } from "../common"
|
||||
import { Context } from "../shared-context"
|
||||
import { CreateFileDTO } from "./mutations"
|
||||
import { CreateFileDTO, GetUploadFileUrlDTO } from "./mutations"
|
||||
|
||||
export interface IFileModuleService extends IModuleService {
|
||||
/**
|
||||
@@ -41,6 +41,43 @@ export interface IFileModuleService extends IModuleService {
|
||||
|
||||
createFiles(data: CreateFileDTO, sharedContext?: Context): Promise<FileDTO>
|
||||
|
||||
/**
|
||||
* This method gets the upload URL for a file.
|
||||
*
|
||||
* @param {GetUploadFileUrlDTO} data - The file information to get the upload URL for.
|
||||
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||
* @returns {Promise<UploadFileUrlDTO>} The upload URL for the file.
|
||||
*
|
||||
* @example
|
||||
* const uploadInfo = await fileModuleService.getUploadFileUrls({
|
||||
* filename: "product.png",
|
||||
* mimeType: "image/png",
|
||||
* })
|
||||
*/
|
||||
|
||||
getUploadFileUrls(
|
||||
data: GetUploadFileUrlDTO,
|
||||
sharedContext?: Context
|
||||
): Promise<UploadFileUrlDTO>
|
||||
|
||||
/**
|
||||
* This method uploads files to the designated file storage system.
|
||||
*
|
||||
* @param {GetUploadFileUrlDTO[]} data - The file information to get the upload URL for.
|
||||
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||
* @returns {Promise<UploadFileUrlDTO[]>} The upload URLs for the files.
|
||||
*
|
||||
* @example
|
||||
* const [uploadInfo] = await fileModuleService.getUploadFileUrls([{
|
||||
* filename: "product.png",
|
||||
* mimeType: "image/png",
|
||||
* }])
|
||||
*/
|
||||
getUploadFileUrls(
|
||||
data: GetUploadFileUrlDTO[],
|
||||
sharedContext?: Context
|
||||
): Promise<UploadFileUrlDTO[]>
|
||||
|
||||
/**
|
||||
* This method deletes files by their IDs.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user