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

Active3 hr before
Viewed126 times

9 Answers


Join Stack Overflow to learn, share knowledge, and build your career.,Still if you are finding issues, you can refer to this working example., Stack Overflow Public questions & answers

   limit: '50mb'

 Pretag team - issue, fix, solve, resolve

There we go! Now we are allowing users to upload multiple files using Axios and VueJS through an AJAX call.,After running through this a few times, uploading files with VueJS and Axios through AJAX becomes a little easier to grasp! Hopefully this tutorial has helped a little. There is always room for expansion and you can do progress uploads and other cool features.,We are now ready to send our files to the server through Axios:

 Pretag team - issue, fix, solve, resolve

Create Service for File Upload,You can change the baseURL that depends on REST APIs url that your Server configures.,Create Component for Upload Files

 Pretag team - issue, fix, solve, resolve

To summarise, sending a file with axios in Node.js requires you to do two important things:,Only if sending files with axios in Node.js would be as easy as taking a walk in the park.,To send a form with axios in Node.js, you have to grab the form boundary and add it to the request.

To construct a form, create a new instance and use the append(name, value) method to add a file and additional fields.

// `form-data` library gives us a similar API in Node.js to the `FormData` interface in the browser
const FormData = require('form-data');

// Create a new form instance
const form = new FormData();

// Append text fields to the form
form.append('productName', 'Node.js Stickers');
form.append('productDescription', 'Cool collection of Node.js stickers for your laptop.');

// `file` can either be a Buffer or a Stream
// ⚠️ don't forget the 3rd argument, the file name, when appending a file
form.append('productImage', file, 'stickers.jpg');
load more v

But the server receives an empty array of files. Why?,I am trying to upload images in this code,The problem was in limit the file size on the server, I increased it and problem was solved

let data = new FormData();

for (var i = 0; i < files.length; i++) {
   let file = files.item(i);
   data.append('images[' + i + ']', file,;

const config = {
   headers: {
      'content-type': 'multipart/form-data'

return'/api/images', data, config)
load more v

Using a separate server backend to handle file uploading may help with scaling in a later stage. Node.Js file upload is the go-to practice around here.,We use the FileReader class to convert our file to Base64 and submit it to the server just like a normal JSON message. ,The file upload mechanism is quite simple and the browser API handles the complexities of the upload.

1 $ create - react - app uploader
2 $ cd uploader
3 $ npm install--save axios
load more v

These can come up with any kind of restrictions;⚠ Amount of size limitation for uploading of internal network of your hosting service provider⚠ Proxy server configurations that clients go through to upload files to your system.⚠ Network distributing rules of the particular web server(like load balancer),File upload is one of the most common features of a web app(actually any kind of app) today. For most of the scenarios, this process is simple and straightforward. But what if most don't involve your situation?,Get smarter at building your thing

 Pretag team - issue, fix, solve, resolve

Axios is a promise-based HTTP client for the browser and Node.js. It has a convenient and modern API simplifying asynchronous HTTP request and response handling. Let’s explore how to download files with Axios in Node.js.,Axios File Download in Node.js,Axios — Download Files & Images in Node.js

Here’s a sample function to download an image:

'use strict'

const Fs = require('fs')
const Path = require('path')
const Axios = require('axios')

async function downloadImage() {
   const url = ''
   const path = Path.resolve(__dirname, 'images', 'code.jpg')
   const writer = Fs.createWriteStream(path)

   const response = await Axios({
      method: 'GET',
      responseType: 'stream'

   return new Promise((resolve, reject) => {
      writer.on('finish', resolve)
      writer.on('error', reject)


Other "using-images" queries related to "How to upload images(large files) to server using axios"