-
Hi, I need to resize the uploaded file with sharp, but how do I access the file body to give to sharp? The image object has only the .move() function, do I need to move the file first?
What should be done? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 7 replies
-
The way i achieve this currently is to use the local file path of the uploaded image: const image = ctx.request.file(...)
const resizedImageData = await sharp(image.tmpPath).resize(500).toBuffer() I've tried digging through the @adonisjs/bodyparser package which allows streaming uploaded files directly (without saving to local filesystem before). Unfortunately i didn't try this yet. |
Beta Was this translation helpful? Give feedback.
-
Has anyone tried with I tried this and both
Any help is appreciated. |
Beta Was this translation helpful? Give feedback.
-
I made a service provider and included a method for forwarding an avatar. public async saveAvatar(
file: MultipartFileContract,
fileName: string,
): Promise<void> {
const ContentType = `${file.type}/${file.subtype}`
const resizedImageData = await sharp(file.tmpPath).resize(500).toBuffer()
await this.client.upload({
CacheControl: 'public,max-age=290304000',
Key: fileName,
Bucket: `${uploadConfig.config.aws.bucket}/${uploadConfig.config.aws.folder}`,
Body: resizedImageData,
ACL: 'public-read',
ContentType,
ContentDisposition: `inline`,
}).promise()
} |
Beta Was this translation helpful? Give feedback.
-
Steps to run above code: Run app.js file using the following command: Server Running! |
Beta Was this translation helpful? Give feedback.
The way i achieve this currently is to use the local file path of the uploaded image:
I've tried digging through the @adonisjs/bodyparser package which allows streaming uploaded files directly (without saving to local filesystem before). Unfortunately i didn't try this yet.