我正在尝试将图像(作为base64格式)从手机间隙应用程序上传到亚马逊s3。图像上传成功,但当我尝试在亚马逊服务器中查看图像时,它会显示为框。我使用以下链接作为参考。
Uploading image to S3 using phonegap, how to?
我还尝试使用以下链接上传图像(作为imageURI),但是它会抛出错误Body.params是必需的
https://github.com/ccoenraets/phonegap-s3-upload/blob/master/client/phonegap-s3-upload/www/app.js
请找到代码片段
// take picture
var options = {
quality: 75,
targetWidth: 320,
targetHeight: 320,
destinationType: 1, // 0 = base 64, 1 = imageURI
sourceType: 1, // 0:Photo Library, 1=Camera, 2=Saved Photo Album
encodingType: 0 // 0=JPG 1=PNG
};
// Take picture using device camera and retrieve image as base64-encoded string
navigator.camera.getPicture(onSuccess,onFail,options);
---------
uploading the image
var imageData = 'data:image/jpeg;base64,'+ $scope.lastPhoto;
var params = {
Key: 'test5.jpg', // for testing purpose
Body: imageData, // base64 data
ContentEncoding: 'base64',
ContentType: 'image/jpeg'
};
var fileName = "" + (new Date()).getTime() + ".jpg";
console.log ('data params' + params.Body);
bucket.upload(params, function(err, data){
$scope.hide($ionicLoading);
var result = err ? 'ERROR!' : 'UPLOADED SUCCESSFULLY...';
var alertPopup = $ionicPopup.alert({
title: 'Amazon Confirmation',
template: 'Result : ' + result
});
答案 0 :(得分:1)
您可以查看此链接how to save canvas data to file
var data = img.replace(/ ^ data:image / \ w +; base64,/,"");
答案 1 :(得分:0)
AWS.config.update({
accessKeyId : 'your-ACCESSKEYID',
secretAccessKey : 'SECRETACCESSKEY'
});
$ cordovaCapture.captureVideo()。then(function(videoData){
$scope.file=videoData[0].name;
var first='file:/storage/sdcard0/DCIM/Camera/';
$cordovaFile.readAsDataURL(first,$scope.file)
.then(function (success) {
var bucket = new AWS.S3({params: { Bucket: 'your-bucket-name' }});
var params = {Key: videoData[0].name, ContentEncoding: 'base64', ContentType: 'video/mp4; charset=UTF-8' , Body: success};
bucket.upload(params).on('httpUploadProgress', function(evt) {
$scope.uploading = true;
$scope.progress = parseInt((evt.loaded * 100) / evt.total)+'%';
console.log("Uploaded :: " + $scope.progress );
$scope.$apply();
}).send(function(err, data) {
$scope.uploading = false;
/*$scope.images.push(data.Location);*/
console.log(data.Location);
$scope.$apply();
});
}, function (error) {
console.log("==========error==========");
console.log(error);
})
})
}