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

Content type missing in multipart post #2864

Closed
mshearer0 opened this issue Mar 27, 2022 · 3 comments
Closed

Content type missing in multipart post #2864

mshearer0 opened this issue Mar 27, 2022 · 3 comments
Labels
issue needs-triaging new issues that need triaging

Comments

@mshearer0
Copy link

Hi, i'm trying to POST formData to Bee from a Vue app and i get:

DEBU[2022-03-25T19:28:50Z] bzz upload dir: store dir err: read tar stream: content-type missing
ERRO[2022-03-25T19:28:50Z] bzz upload dir: store dir

const response = await this.$http.post(${this.$config.BZZ_ENDPOINT}/bzz, formData, {headers: {'swarm-postage
-batch-id':'xxx','Content-Type':'multipart/form-data'}})

Any help appreciated.

@mshearer0 mshearer0 added the needs-triaging new issues that need triaging label Mar 27, 2022
@bee-runner bee-runner bot added the issue label Mar 27, 2022
@mshearer0 mshearer0 changed the title General problem description Content type missing in multipart post Mar 27, 2022
@agazso
Copy link
Member

agazso commented Mar 30, 2022

The /bzz endpoint expects either a tar file to be uploaded or a multipart form. When you use the multipart/form-data each part of the multipart has to be a file with the content-type header set correctly.

If you are using Javascript it may be easier to use the https://github.com/ethersphere/bee-js library which provides convenient wrapper functions around the API so that you don't have to deal with details like this.

@mshearer0
Copy link
Author

Thanks. I understand the browser should set the content types automatically when using a multipart form but when I look at the POST it doesn’t seem to - can I force this?

@agazso
Copy link
Member

agazso commented Mar 30, 2022

The formData variable that you pass for uploading needs to be created properly, something like this:

const formData = new FormData()
formData.append("filename", file) 

The file object must be of type File. Then its type property is used as the mime type. Usually in a form you can get it from the list of selected files from event.target.files as an array.

However this is not really related to Bee itself, but rather how to correctly create FormData objects in Javascript. In order to avoid issues like this I highly recommend to use the bee-js library I mentioned above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue needs-triaging new issues that need triaging
Projects
None yet
Development

No branches or pull requests

2 participants