I am trying to upload multiple type of files to S3 in sails js Files are as Follow : VehicleImages, VehicleVideos, VehicleDocuments I am passing these three type of files with attribute name with same name as these files to my server via multipart/form-data
My approach is to upload one type of file lets say VehicleImages by using await Then upload the next and then the next.
I am unable to do so since i get the error :
{
"cause": {
"code": "EMAXBUFFER",
"message": "EMAXBUFFER: An upstream (`vehicleDocuments`) timed out before it was
plugged into a receiver. It was still unused after waiting 4500ms.
You can configure this timeout by changing the `maxTimeToBuffer`
option.\n\nNote that this error might be occurring due to an earlier
file upload that is finally timing out after an unrelated server
error."
},
"isOperational": true,
"code": "EMAXBUFFER"
}
This is my code for policies folder
VehicleController: {
create: ["isLoggedIn", "vehicleImages", "vehicleKey", "vehicleDocuments"],
update: ["isLoggedIn", "vehicleImages", "vehicleKey", "vehicleDocuments"],
"*": "isLoggedIn",
},
This is the helper function that i am using in my policies
fn: async function (inputs) {
const { req, res, proceed, fieldName, folderName, setParams } = inputs;
const skipperUpstream = req.file(fieldName);
const file = skipperUpstream._files[0];
if (!file) {
// `skipperUpstream.__proto__` is `Upstream`. It provides `noMoreFiles()` to stop receiving files.
// It also clears all timeouts: https://npmdoc.github.io/node-npmdoc-skipper/build/apidoc.html#apidoc.element.skipper.Upstream.prototype.noMoreFiles
skipperUpstream.noMoreFiles();
return proceed();
}
let timestamp = Date.now();
let uploadedFiles = await sails.upload(req.file(fieldName), {
adapter: require("skipper-s3"),
key: process.env.AWS_ACCESS_KEY_ID,
secret: process.env.AWS_SECRET_ACCESS_KEY,
bucket: process.env.AWS_BUCKET_NAME,
region: "us-east-2",
headers: {
"x-amz-acl": "public-read",
},
// maxBytes: sails.config.custom.maxFileSize,
// change folder and file name
dirname: folderName,
saveAs: function (__newFileStream, next) {
next(undefined, timestamp + __newFileStream.filename);
},
});
sails.log("filesUploaded In Helper", uploadedFiles);
if (uploadedFiles) {
uploadedFiles.forEach((file) => {
file.fd =
process.env.AWS_BUCKET_URL +
((folderName ? folderName + "%5C" : "") +
timestamp +
file.filename.replaceAll("\\", "%5C"));
});
sails.log("filesUploaded", uploadedFiles[0]);
req.files = uploadedFiles;
setParams && setParams(uploadedFiles);
}
return proceed();
},
My aim to upload large files (images, videos, documents) from react application to s3 bucket . How can I do this?