The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/app/api/server/lib/getUploadFormData.js

36 lines
780 B

import Busboy from 'busboy';
export const getUploadFormData = async ({ request }) =>
new Promise((resolve, reject) => {
const busboy = new Busboy({ headers: request.headers });
const fields = {};
busboy.on('file', (fieldname, file, filename, encoding, mimetype) => {
const fileData = [];
file.on('data', (data) => fileData.push(data));
file.on('end', () => {
if (fields.hasOwnProperty(fieldname)) {
return reject('Just 1 file is allowed');
}
fields[fieldname] = {
file,
filename,
encoding,
mimetype,
fileBuffer: Buffer.concat(fileData),
};
});
});
busboy.on('field', (fieldname, value) => {
fields[fieldname] = value;
});
busboy.on('finish', () => resolve(fields));
request.pipe(busboy);
});