Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 如何使用ionic 4中的签名url和ionic camera插件在s3中上传图像_Angular_Ionic Framework_Amazon S3_Ionic4 - Fatal编程技术网

Angular 如何使用ionic 4中的签名url和ionic camera插件在s3中上传图像

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,

我正在使用ionic原生插件上传带有s3签名url的图像。摄像头插件生成base64格式的图像,因此我无法以正确的格式上传

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();
}
希望这有帮助