I am trying to generate an uplaod presigned url where frontend is required to send the content type of file.
I see that if fronend doesnt send this content type and i remove content type in params everything works fine,
but in bucket the object has type as blank white space no type mentioned.
so i thought while downloading or while getting the object through presignedurl and get it will give some error
but still everything works fine
only thing i can think of is we can use that content type in backend for validation and can limit uplaod to specific content type like images videos or something else?
Can anyone please explainthe real use case
Thankss.
app.post("/api/posts/pre", async (req, res) => {
const bucketName = 'usman.test.bucket';
const { fileName, fileType } = req.body; // Get file name and file type from form data
// /frontend is responsible for providing the fileType information, while the backend handles the generation of the fileName and the pre-signed URL. This separation of concerns ensures that the application is more modular and maintainable.
// /If the frontend doesn't provide the fileType, the backend can assume a default file type, such as application/octet-stream, which is a generic binary file type.
try {
const params = {
Bucket: bucketName,
Key: fileName,
ContentType: fileType,
};
const command = new PutObjectCommand(params);
const signedUrl = await getSignedUrl(s3, command, { expiresIn: 3600 });
res.json({ presignedUrl: signedUrl });
} catch (error) {
console.error('Error generating pre-signed URL:', error);
res.status(500).send('Error generating pre-signed URL');
}
});