[Vuejs]-Upload file with Sails JS and Vue JS

0šŸ‘

Thanks you for your answers !

I think itā€™s a front-end problem. When I make a ā€œconsole.logā€ on ā€œinputsā€ in my action:

{ imgFile: 
   Upstream {
     _fatalErrors: [],
     isNoop: true,
     _files: [],
     timeouts: { untilFirstFileTimer: [Object], untilMaxBufferTimer: [Object] },
     _readableState: 
      ReadableState {
        objectMode: true,
        highWaterMark: 16,
        buffer: [Object],
        length: 0,
        pipes: null,
        pipesCount: 0,
        flowing: null,
        ended: false,
        endEmitted: false,
        reading: false,
        sync: true,
        needReadable: false,
        emittedReadable: false,
        readableListening: false,
        resumeScheduled: false,
        destroyed: false,
        defaultEncoding: 'utf8',
        awaitDrain: 0,
        readingMore: false,
        decoder: null,
        encoding: null },
     readable: true,
     domain: null,
     _events: { error: [Function] },
     _eventsCount: 1,
     _maxListeners: undefined,
     fieldName: 'NOOP_imgFile' },
  titre: 'inputs inputs inputs inputs',
  description: 'inputs inputs inputs',
  contenue: 'inputs inputs inputs',
  postDate: '2019-12-21T09:13',
  etiquette: 1 }

On the Chrome dev tool :

response of the tool

I think is not a websocket request is XMLHttpRequest (type;xhr).

0šŸ‘

module.exports = {


  friendlyName: 'Update profile avatar',


  description: '',


  inputs: {

  },


  exits: {

    success: {
      responseType: 'redirect'
    },

    failure: {
      responseType: 'redirect'
    },

    unhandleError: {
      responseType: 'redirect',
    }

  },


  fn: async function (inputs, exits) {

    let req = this.req;
    let res = this.res;

    req.file('avatar').upload({
        saveAs: fileName,
        dirname: require('path').resolve(sails.config.appPath, 
                'assets/uploads')
    }, function whenDone(err, uploadedFile) { 
        // your code here
    });
  }


};

This is my code in controller when using req.file(ā€˜file-nameā€™).upload() function. No need to define file in inputs because using req

Leave a comment