Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File upload with Multer. #6

Open
roccomuso opened this issue Jan 20, 2016 · 2 comments
Open

File upload with Multer. #6

roccomuso opened this issue Jan 20, 2016 · 2 comments

Comments

@roccomuso
Copy link
Owner

Card header image uploaded as temporary Image even if a card is rejected during validation.

"If req.body is empty, it means that the client sent the file before sending the new_file_name field.
There is nothing we can do about it in multer."

See expressjs/multer#299 and expressjs/multer#146

@Tyrone2333
Copy link

In my Request payload:

------WebKitFormBoundary2xMRe7hq1ThhErY2
Content-Disposition: form-data; name="file"; filename="qr.png"
Content-Type: image/png
------WebKitFormBoundary2xMRe7hq1ThhErY2
Content-Disposition: form-data; name="author"
root
------WebKitFormBoundary2xMRe7hq1ThhErY2
Content-Disposition: form-data; name="username"
root
------WebKitFormBoundary2xMRe7hq1ThhErY2--

The file was sent before the body,so I can't got req.body in multer.diskStorage, I tried everything,finally
I found create new FormData,then use axios to send it to Server could got req.body.My code:

 let formData = new FormData()
 formData.append("author", _this.$store.state.user.user.username)
 formData.append("type", "article")
 formData.append("file", $file)  // Put it at the bottom
 axios({
        url: process.env.BASE_API + "/article/upload_img",
        method: 'post',
        data: formData,
        headers: {'Content-Type': 'multipart/form-data', 'token': token},
  }).then((res) => { }

New Request payload:

------WebKitFormBoundaryEbY70DntTXeXcwri
Content-Disposition: form-data; name="author"
root
------WebKitFormBoundaryEbY70DntTXeXcwri
Content-Disposition: form-data; name="type"
article
------WebKitFormBoundaryEbY70DntTXeXcwri
Content-Disposition: form-data; name="file"; filename="qr.png"
Content-Type: image/png
------WebKitFormBoundaryEbY70DntTXeXcwri--

I hope this is useful to you.

@Great-hijack
Copy link

This is so helpful for me.
It's working well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants