FEDev
FEDev

Reputation: 135

how to upload images(large files) to server using axios

I'm new to this community. Actually, I'm doing a small project using the React, and my server is running with the express and node js with mongodb database.

For the smaller files I'm able to communicate with the server as normal.But as I upload a larger file I'm unable to send the data to the server.An empty object is sent to the server.

And the client side its showing the error of

"No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8000' is therefore not allowed access. The response had HTTP status code 413."

I've searched for the solution in the internet for hours, but I havent got any solution.

can anyone help me out from this...?

Upvotes: 5

Views: 9783

Answers (2)

sudheeshcm
sudheeshcm

Reputation: 3418

Did you check your request being sent to the backend? Whether the image details are sent along with it.

Seems like you are doing a cross domain request. Make sure that you have the above headers set at the backend for the response.

Still if you are finding issues, you can refer to this working example. https://github.com/mzabriskie/axios/blob/master/examples/upload/index.html

Upvotes: 1

A K
A K

Reputation: 1674

app.use(bodyParser.json({limit: '50mb'}));

You might need to use middleware to set the size limits of uploads.

Upvotes: 6

Related Questions