Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

File upload issue: 500 error or corrupted file. #5151

Closed
nikhiltechzillaindiacom opened this issue May 8, 2019 · 3 comments
Closed

File upload issue: 500 error or corrupted file. #5151

nikhiltechzillaindiacom opened this issue May 8, 2019 · 3 comments

Comments

@nikhiltechzillaindiacom
Copy link

nikhiltechzillaindiacom commented May 8, 2019

When I try to upload file using /_matrix/media/r0/upload url with Content-Type:image/png or image/jpeg, server throws 500 error.
If I make the same request without Content-Type, server return success but when i try to access that file using /_matrix/media/r0/download/{serverName}/{mediaId} url, the file I get in response in corrupted.

Below is the code that i have used to make requets
var headers = { "Content-Type": "image/png", }
let blob = atob(files[0].base64)
axios.post(url, blob, { headers }).then(res => { console.log(res) }) .catch(err => { console.log(err) })

I have tried this with postman with same request parameters it works there
I have compared the request of postman and riot.im, it seems to be the same.
I have no idea why it is failing.

can someone explain me this api?

POST /_matrix/media/r0/upload?filename=War+and+Peace.pdf HTTP/1.1
Content-Type: application/json
"<bytes>"

what does "<bytes>" means in this api and how can i get a file in this format in javascript ?

Thank you!

@Sharparam
Copy link

I wonder if this can be related to #5114?

Does axios automatically add the Content-Length header, and if not, does it work if you add it manually?

@nikhiltechzillaindiacom
Copy link
Author

Does axios automatically add the Content-Length header?

No

does it work if you add it manually?

No.
It throws Refused to set unsafe header "Content-Length" error.

explanation

@nikhiltechzillaindiacom
Copy link
Author

It worked from backend

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

No branches or pull requests

2 participants