我想将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));
答案 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
完成什么。