gpt4 book ai didi

android - cordova/phonegap 图像上传到 Amazon s3

转载 作者:行者123 更新时间:2023-11-29 01:24:52 26 4
gpt4 key购买 nike

我正在尝试将图像(作为 base64 格式)从电话间隙应用程序上传到 amazon s3。图片上传成功,但是当我尝试在亚马逊服务器中查看图片时,它显示为方框。我使用以下链接作为引用。

Uploading image to S3 using phonegap, how to?

我还尝试使用下面的链接上传图片(作为 imageURI),但它会抛出错误 Body.params is required

https://github.com/ccoenraets/phonegap-s3-upload/blob/master/client/phonegap-s3-upload/www/app.js

请找到代码 fragment ,

// 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
});

最佳答案

你能查看这个链接吗 how to save canvas data to file

var data = img.replace(/^data:image/\w+;base64,/, "");

关于android - cordova/phonegap 图像上传到 Amazon s3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34619880/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com