Multiple file upload in Sails.js with sails-hook-uploads from Vue.js: ETIMEOUT

552 Views Asked by At

I am trying to upload mutliple files via patch from my Vue frontend to my Sails backend. For each product there could be a single thumbnail and multiple detail images. For the request from Vue I set up a FormData Object, which includes the images (1 thumbnail, n detail images)

function buildMultipartFormDataObject(data) {
  let formData = new FormData()
  //append text before images
  if(data.thumbnail) formData.append('thumbnail', data.thumbnail)
  if(data.images) {
    for(let i = 0; i < data.images.length; i++) {
      formData.append(`images[${ i }]`, data.images[i])
    }
  }
  return formData
}

In my sails Controller I am doing the following for uploading the files

module.exports = async function update (req, res) {
  // ...
  let productImagesDirname = require('path').resolve(sails.config.appPath, 'assets/images/products/')

  //uploadOne() and upload() are from 'sails-hook-uploads'
  let uploadedThumbnail = await sails.uploadOne(req.file('thumbnail'), { dirname: productImagesDirname })
  let uploadedImages = await sails.upload(req.file('images'), { dirname: productImagesDirname })

My thumbnail is uploading as expected but for the images I get

Error: EMAXBUFFER: An Upstream (images[0]) timed out before it was plugged into a receiver. It was still unused after waiting 4500ms. You can configure this timeout by changing the maxTimeToBuffer option.

for each image (image[0] ... image[n]) and right after

Error: ETIMEOUT: An Upstream (images) timed out waiting for file(s). No files were sent after waiting 10000ms.

even if I only want to upload the images (commented out thumbnail upload in sails&vue). So obviously sails is missing images in the Uploadstream?

The _files field of the req.file('thumbnail') Upstream contains a stream object

debug: Upstream {
  _fatalErrors: [],
  _files: [ { stream: [Object], status: 'bufferingOrWriting' } ],

The _files field of the req.file('images') Upstream is empty but I do not get why

debug: Upstream {
  _fatalErrors: [],
  _files: [],

Any ideas out there?

0

There are 0 best solutions below