代码之家  ›  专栏  ›  技术社区  ›  KVISH

上传文件SailsJS

  •  0
  • KVISH  · 技术社区  · 8 年前

    uploadData(req, res) {
      Logger.info(req.file('file'));
    
      req.file('file').upload({
        dirname:'../../tmp',
        saveAs:"hello"
      },function onUploadComplete(err,files){
        if(err){
          console.log(err);
          return res.serverError(err);
        }
        if(!files.length) {
          return res.serverError(new Error('No file Uploaded'))
        }
        res.ok(files);
      });
    },
    

    2018-09-17T16:55:07.736Z] info:  info: Custom response `res.serverError()` called with an Error: Error: Request aborted
        at IncomingMessage.onReqAborted (/home/ubuntu/server/node_modules/multiparty/index.js:183:17)
        at IncomingMessage.emit (events.js:182:13)
        at IncomingMessage.EventEmitter.emit (domain.js:442:20)
        at abortIncoming (_http_server.js:444:9)
        at socketOnClose (_http_server.js:437:3)
        at Socket.emit (events.js:187:15)
        at Socket.EventEmitter.emit (domain.js:442:20)
        at TCP._handle.close (net.js:599:12)
    

    我做错什么了?我按照以下说明进行操作:

    Sails Js Read uploaded file content

    https://sailsjs.com/documentation/reference/request-req/req-file

    https://sailsjs.com/documentation/concepts/file-uploads

    1 回复  |  直到 8 年前
        1
  •  0
  •   KVISH    8 年前

    这是有效的:

    uploadData(req, res) {
      Logger.info(req.file('file'));
    
      return req.file('file').upload({
        adapter: require('skipper-disk'),
        saveAs:"hello"
      },function onUploadComplete(err,files){
        if(err){
          console.error("ERROR");
          console.log(err);
          return res.serverError(err);
        }
        if(!files.length) {
          return res.serverError(new Error('No file Uploaded'))
        }
        res.ok(files);
      });
    },
    
    推荐文章