My current project involves uploading basic documents using busboy / express.js to google cloud.
However, I encountered this error message:
Error: Cannot find module 'busboy/lib/types/node_modules/dicer'
Here is the code snippet for the upload request:
// Uploading a document for claim
exports.uploadDocument = (req, res) => {
const BusBoy = require("busboy");
const path = require("path");
const os = require("os");
const fs = require("fs");
const busboy = new BusBoy({ headers: req.headers });
let DocumentToBeUploaded = {};
let DocumentFileName;
// Modify this section to handle pdfs and docs etc
busboy.on("file", (fieldname, file, filename) => {
console.log(fieldname, file, filename);
const documentExtension = filename.split(".")[
filename.split(".").length - 1
];
// 32756238461724837.png
DocumentFileName = `${Math.round(
Math.random() * 1000000000000
).toString()}.${documentExtension}`;
const filepath = path.join(os.tmpdir(), DocumentFileName);
DocumentToBeUploaded = { filepath, mimetype };
file.pipe(fs.createWriteStream(filepath));
});
busboy.on("finish", () => {
admin
.storage()
.bucket()
.upload(DocumentToBeUploaded.filepath, {
resumable: false,
metadata: {
metadata: {
contentType: DocumentToBeUploaded
}
}
})
.then(() => {
const docUrl = `https://firebasestorage.googleapis.com/v0/b/${config.storageBucket}/o/${DocumentFileName}?alt=media`;
return db.doc(`/users/${req.Claim.ClaimId}`).update({ docUrl });
})
.then(() => {
return res.json({ message: "document uploaded successfully" });
})
.catch(err => {
console.error(err);
return res.status(500).json({ error: "something went wrong" });
});
});
busboy.end(req.rawBody);
};
I am currently attempting to upload a basic text document. It seems like a simple task, so I must be overlooking a minor error somewhere.
Any assistance would be greatly appreciated. Thank you :)