将离子3应用程序的pdf文件上传到亚马逊s3桶

时间:2017-12-13 12:12:17

标签: amazon-s3 ionic3

我想将pdf文件上传到amazon s3存储桶。但只有文件路径上传而不是文件

var filepath = "";
var that = this;
this.fileChooser.open()
  .then(uri => {
    console.log(uri);
    filepath = uri;

    var fileName = 'File_' + this.global.gerUniqueString() + ".pdf";

    var AWSService = window.AWS;
    AWSService.config.accessKeyId = this.global.accessKeyId;
    AWSService.config.secretAccessKey = this.global.secretAccessKey;
    AWSService.config.region = 'ap-south-1';
    var bucket = new AWSService.S3({ params: { Bucket: this.global.bucketName } });
    var body = 'data:application/pdf', base64, filepath;
    var params = { Key: fileName, Body: body };
    bucket.upload(params, function (err, data) {

      console.log(err, data);

    });

  })
  .catch(e => console.log(e));

1 个答案:

答案 0 :(得分:0)

您的问题在于此代码:

var body = 'data:application/pdf', base64, filepath;
var params = { Key: fileName, Body: body };

更改为:

var params = {Key: filename, ContentType: 'application/pdf', Body: filepath};

我不确定您要使用base64完成什么。