Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js putObject使Nodejs中服务器上的对象变大_Node.js_Amazon Web Services_Amazon S3_Meteor - Fatal编程技术网

Node.js putObject使Nodejs中服务器上的对象变大

Node.js putObject使Nodejs中服务器上的对象变大,node.js,amazon-web-services,amazon-s3,meteor,Node.js,Amazon Web Services,Amazon S3,Meteor,我使用Nodejs尝试使用awsdk将映像推送到S3实例。目前,它从客户机上读取文件,然后将其保存在服务器上(我使用的是meteor框架)。我希望将其推送到S3服务器,而不是保存在meteor服务器上。当我尝试将其迁移过来时,在S3上的图像似乎增加了约30%。如果我试着从S3下载它们,图像也不再可见,所以看起来好像它改变了编码或其他什么 以下是在客户端加载文件的代码: saveFile = function( blob, name, path, type, callback ) { var

我使用Nodejs尝试使用awsdk将映像推送到S3实例。目前,它从客户机上读取文件,然后将其保存在服务器上(我使用的是meteor框架)。我希望将其推送到S3服务器,而不是保存在meteor服务器上。当我尝试将其迁移过来时,在S3上的图像似乎增加了约30%。如果我试着从S3下载它们,图像也不再可见,所以看起来好像它改变了编码或其他什么

以下是在客户端加载文件的代码:

saveFile = function( blob, name, path, type, callback ) {
  var fileReader = new FileReader();
  var method;
  var encoding = 'binary';
  var type = type || 'binary';

  switch( type ) {
    case 'text':
      method = 'readAsText';
      encoding = 'utf8';
      break;
    case 'binary':
      method = 'readAsBinaryString';
      encoding = 'binary';
      break;
    default:
      method = 'readAsBinaryString';
      encoding = 'binary';
      break;   
  }

  // Call the save function on the server after the file has been read.
  fileReader.onload = function( file ) {
    console.log( "File loaded..." );
    Meteor.call( 'saveFile', file.srcElement.result, name, path, encoding, callback );
  }

  // Read the file
  fileReader[ method ]( blob );
}
在服务器端:

  saveFile: function( file, name, path, encoding ) {
    s3.createBucket({Bucket: bucketName}, function() {
      var params = {Bucket: bucketName, Key: keyName, ContentType: 'binary', ContentEncoding: 'utf8', Body: file};
      s3.putObject(params, function(err, data) {
        if (err)
          console.log(err)
        else
          console.log("Successfully uploaded data to " + bucketName + "/" + keyName);
      });
    });

我找到了解决方案,它是将“file”对象封装在

new Buffer()

很简单,但是很难找到哦

看起来像是你的base64编码