You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Searched both open and closed issues for duplicates of this issue
Title adequately and concisely reflects the feature or the bug
Feature Request
Use Case
By adding the multipartFileHandler or multipartHandler to the bodyParser options, the ordinary process of formidable does not continue (the form.handlePart(part) would not be called anymore). So, we must write our handling function to save the incoming file for example.
server.use(restify.plugins.bodyParser({// other options// ...multipartFileHandler: function(part){const{mime}=part;constfileType: string=mime.split('/').pop();if(fileType==='jpg'||fileType==='png'||fileType==='jpeg'){part.on('data',buffer=>{fs.writeFile(filePath,buffer,(err)=>{if(err){console.log(err);}else{console.log("The file was saved:",filename);// form.emit('file', part.name, theSavedFile);}});});}else{console.log('incorrect file type:',fileType);}},// ...});
Besides, this method leaves the request.files to be an empty object {}. As we can not call the form.emit('file', part.name, theSavedFile) to ask the formidable: "the {[part.name]: theSavedFile} was successfully received, please add it the the files object".
Example API
We can easily run this snippet and save the file like a piece of cake.
server.use(restify.plugins.bodyParser({multiples: true,
uploadDir,multipartFileHandler: function(part,req,form){// <-- the third argument can be addedconst{mime}=part;constfileType: string=mime.split('/').pop();if(fileType==='jpg'||fileType==='png'||fileType==='jpeg'){form.handlePart(part);// <--- this line can be used.}else{console.log('incorrect file type:',fileType);}}})
Are you willing and able to implement this?
It's not so hard. However, I wrote a snippet to inject "form" into the functions.
The text was updated successfully, but these errors were encountered:
Feature Request
Use Case
By adding the
multipartFileHandler
ormultipartHandler
to thebodyParser
options, the ordinary process of formidable does not continue (theform.handlePart(part)
would not be called anymore). So, we must write our handling function to save the incoming file for example.Besides, this method leaves the
request.files
to be an empty object{}
. As we can not call theform.emit('file', part.name, theSavedFile)
to ask the formidable: "the{[part.name]: theSavedFile}
was successfully received, please add it the thefiles
object".Example API
We can easily run this snippet and save the file like a piece of cake.
Are you willing and able to implement this?
It's not so hard. However, I wrote a snippet to inject "form" into the functions.
The text was updated successfully, but these errors were encountered: