请教一个nodejs上传问题
发布于 1年前 作者 kinglo 750 次浏览

我在做android应用时需要将crashlog (crash-1388057064989.cr文件)上传至服务器,服务器是用 nodejs 写的 上传一般文件都没问题!就是上传crashlog时会出错?

服务器代码

 var self = this
          , form = new formidable.IncomingForm()
          , uploadedFile
          , savedFile;
      // Handle each part of the multi-part post
      form.onPart = function (part) {
          // Handle each data chunk as data streams in
          part.addListener('data', function (data) {
              // Initial chunk, set the filename and create the FS stream
              if (!uploadedFile) {
                  uploadedFile = encodeURIComponent(part.filename);
                  savedFile = fs.createWriteStream(path.join('public', 'mylog', uploadedFile));
                console.log("000000000"+uploadedFile);
              }
              savedFile.write(data);
          });
          // The part is done
          part.addListener('end', function () {
              var err;
              // If everything went well, close the FS stream
              if (uploadedFile) {
                  savedFile.end();
              }
              // Something went wrong
              else {
                  err = new Error('Something went wrong in the upload.');
                  self.error(err);
              }
          });

报错

Error: Something went wrong in the upload.
at Stream. (/Users/yjl/reekr/nodejs/myblog/crashlog/app/controllers/uploads.js:44:25)
at Stream.EventEmitter.emit (events.js:92:17)
at MultipartParser.parser.onPartEnd (/Users/yjl/reekr/nodejs/myblog/crashlog/node_modules/formidable/lib/incoming_form.js:364:14)
at callback (/Users/yjl/reekr/nodejs/myblog/crashlog/node_modules/formidable/lib/multipart_parser.js:102:31)
at MultipartParser.write (/Users/yjl/reekr/nodejs/myblog/crashlog/node_modules/formidable/lib/multipart_parser.js:260:15)
at IncomingForm.write (/Users/yjl/reekr/nodejs/myblog/crashlog/node_modules/formidable/lib/incoming_form.js:141:34)
at IncomingMessage. (/Users/yjl/reekr/nodejs/myblog/crashlog/node_modules/formidable/lib/incoming_form.js:110:12)
at IncomingMessage.EventEmitter.emit (events.js:95:17)
at IncomingMessage. (_stream_readable.js:746:14)
at IncomingMessage.EventEmitter.emit (events.js:92:17)

请高人指点为下?是不是和这个文件格式有关系? android端上传图片是没有问题的!

1 回复

我知道原因了,因为文件长度为0

回到顶部