I am using digital ocean for storing images. It was all working fine till I was using Firebase. I moved to MongoDB and Node js server. Now I am uploading images and when its more than 5 MBs, I get URL which is missing https:// and also appears somewhere in between the URL.
I was expecting https://my-bucket.nyc3.digitaloceanspaces.com/folderName/image_picker_44B4654D-A164-41A8-B86E-4844B3699137-88682-00002E3606926DB8.jpg And I am getting nyc3.digitaloceanspaces.com/my-bucket/folderName/image_picker_44B4654D-A164-41A8-B86E-4844B3699137-88682-00002E3606926DB8.jpg
My code snippet is
const file = req.files.image;
const businessId = req.body.businessId;
const buffer = fs.readFileSync(req.files.image.filepath);
const spacesEndpoint = new aws.Endpoint('nyc3.digitaloceanspaces.com');
const s3 = new aws.S3({
endpoint: spacesEndpoint,
region: 'nyc3',
credentials: {
accessKeyId: 'uuuuuuuuuuuuuuuuuu',
secretAccessKey: 'YYYYYYYYYYYYYY',
},
});
s3.upload(
{
Bucket: 'dummy-spaces', // Add bucket name here
ACL: 'public-read', // Specify whether anyone with link can access the file
Key: `businessPhotosOfWork/${file.originalFilename}`, // Specify folder and file name
Body: buffer,
},
{},
).send((err: AWSError | null, data: any) => {
console.log(`${err}`);
if (err) return res.status(500).send({ message: `${err}` });
// Unlink file
fs.unlinkSync(file.filepath);
return successResponse(res, 'Operation Successful', { url: data.Location });
// Return file url or other necessary details
});
},