authentication upload based on data in the multipart request body
See original GitHub issueHi,
I am building a file manager and I need to check if the current user is authorized to upload a new file to a given project, thus I need data on each file upload. I am using flow.js on the client-side and I can send extra data on the request body
var flow = new Flow({
target: '/api/photo/redeem-upload-token',
query: {
sessionToken: '...',
projecId: 'huy12387yh1209'
}
});
The problem is that as the encoding is multipart
, the request body is only parsed by multer, and not by any other middleware parser, so that I have no access to the extra data before multer uploading the file.
What is the best way of doing this? Should I send the projectId
in an http header?
Thanks in advance
I found a related issue, but it is already closed
Issue Analytics
- State:
- Created 8 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Uploading and copying objects using multipart upload
Multipart upload allows you to upload a single object as a set of parts. Each part is a contiguous portion of the object's...
Read more >Multipart Requests - Swagger
Multipart requests combine one or more sets of data into a single body, separated by boundaries. You typically use these requests for file...
Read more >How to upload file to server with HTTP POST multipart/form ...
I want to upload SQLite database via PHP web service using HTTP POST request with MIME type multipart/form-data & a string data called...
Read more >HMAC authenticated API calls with multipart/form-data file ...
I'm attempting to write a bash script as an example API call using cURL. I already have one that works without file uploads...
Read more >File uploads (profile image, simple, resumable uploads)
{rest of bearer token} Content-Type: multipart/form-data; ... uses the legacy ID/Key-based authentication system, then the HTTP request URL will have your ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
http-errors
is a great module for constructing errors with a specific status code.Note that the above will only work if
sessionToken
andprojectId
is sen’t over the wire before the file in question. You might be required to tweak flow to get that to work. The trick is to add the fields before the files to theFormData
object.Hey I am still now able to understand what you meant by that.
This is my multer module:
Now after this, on my route I am doing this,
I am getting undefined for req.body which is correct as express will not parse multiform data. How can I make this field secure? I am sending an auth token with the name =“token” and value as a jwt object but I am not able to get it in the req.body. I want to upload an image as well as the key value pair for authentication.
PS: The image is uploaded successfully and everything else is working fine.