【发布时间】:2019-07-02 20:30:57
【问题描述】:
我正在使用 Angular 4/Ionic4。我需要使用 file_URI 而不是 data_URL 将图像发送到数据库,因为数据 URL 以 base64 编码,占用太多内存。最初我使用 base64,它完全可以正常工作,但我的前辈告诉我对 FILE_uri 做同样的事情,我挣扎了 2 天来显示图像并将其发送到数据库。我尝试了 normalizing-URL、domsanitizer、web-view 但是没用。检查upload() 代码是否正确将图像发送到数据库
<img [src]="image"/>
image:any;
take(){
const options: CameraOptions = {
quality: 100,
destinationType: this.camera.DestinationType.FILE_URI,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE,
saveToPhotoAlbum: false
}
this.camera.getPicture(options).then((imageData) => {
// this.success = 'getting image is successful';
this.image =imageData;
// this.imageURI = this.webview.convertF(imageData);
}, (err) => {
this.err = err;
});
}
upload(){
let url="https://staging-api.kofluence.com/influencer/v1/profile";
let postData=new FormData();
postData.append('file',this.image);
let data:Observable<any>=this.http.post(url,postData);
data.subscribe((result)=>{
console.log(result);
}
);
}
【问题讨论】:
-
在这里试试LINK,然后搜索“我们的图片上传基础”和“添加新图片”。 “我们没有使用 base64,而是图像的真实 FILE_URI”,这是你在找什么?
-
是的。你可以为我的东西张贴代码吗。
-
老实说,我不能,我从不使用 Ionic,所以我可能会误会你。
标签: angular ionic-framework ionic4