Angular 如何使用ionic 4中的签名url和ionic camera插件在s3中上传图像
我正在使用ionic原生插件上传带有s3签名url的图像。摄像头插件生成base64格式的图像,因此我无法以正确的格式上传Angular 如何使用ionic 4中的签名url和ionic camera插件在s3中上传图像,angular,ionic-framework,amazon-s3,ionic4,Angular,Ionic Framework,Amazon S3,Ionic4,我正在使用ionic原生插件上传带有s3签名url的图像。摄像头插件生成base64格式的图像,因此我无法以正确的格式上传 takePhoto() { const options: CameraOptions = { quality: 50, destinationType: this.camera.DestinationType.DATA_URL, encodingType: this.camera.EncodingType.JPEG,
takePhoto() {
const options: CameraOptions = {
quality: 50,
destinationType: this.camera.DestinationType.DATA_URL,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE,
correctOrientation: true,
sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
};
this.camera.getPicture(options).then((imageData) => {
this.img = 'data:image/jpeg;base64,' + imageData;
this.uploadProfile();
}, (err) => {
console.log(err);
});
}
uploadProfile() {
const phone = localStorage.getItem('phone');
const imageName = phone + '.jpg';
this.profileService.getPresignedUrl(imageName).subscribe(res => {
console.log(res.urls[0]);
this.profileService.uploadProfile(res.urls[0], this.img).subscribe(data => {
console.log('Successfully Uploaded');
});
});
}
我正在尝试这些方法,但以文本格式存储有点晚了,但我会在这里给出答案以防万一。 使用文件\u URI作为camera.DestinationType。 然后使用XMLHttpRequest将文件_URI转换为blob
takePhoto() {
const options: CameraOptions = {
quality: 50,
destinationType: this.camera.DestinationType.FILE_URI,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE,
correctOrientation: true,
sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
};
this.camera.getPicture(options).then((imageData) => {
this.imageDataToBlob(imageData)
this.uploadProfile();
}, (err) => {
console.log(err);
});
}
图像数据到blob
imageDataToBlob(imageData) {
let xhr = new XMLHttpRequest();
xhr.open('GET', imageData);
xhr.responseType = 'blob';
xhr.onload = () => {
let blobImage = xhr.response;
}
xhr.send();
}
希望这有帮助