How the Cloudflare storage works
upload
method is utilized in a controller to handle file uploads. The uploaded files, along with additional parameters, are passed to the UploadService
which then processes and stores the files in a Cloudflare storage.
@UploadedFiles() files: Array<Express.Multer.File>
: This decorator extracts the uploaded files from the client request.@Body('folder') folder: string
: Extracts the folder name from the request body where the files should be uploaded.@Req() req: Request
: Captures the entire request object.const mappedFiles: File[]
: Maps the received Express.Multer.File
objects to a simplified File
object format that’s compatible with the UploadService
.const filesPaths = await this.uploadService.upload(mappedFiles, folder, req['user'])
: Invokes the upload
method of UploadService
, passing the mapped files, folder name, and user information from the request. The files are uploaded to Cloudflare storage.await new Promise((resolve) => setTimeout(resolve, 3000))
: Adds a slight delay before responding, this might be to ensure that file processing is completed.return filesPaths
: Returns the paths of the uploaded files to the client.