Javascript Angular 7以base64格式将图像上载到s3
在Ionic 4.7应用程序中,尝试从Cordova摄像头插件上载图像 摄像头插件的输出是base64图像数据Javascript Angular 7以base64格式将图像上载到s3,javascript,typescript,amazon-s3,file-upload,ionic4,Javascript,Typescript,Amazon S3,File Upload,Ionic4,在Ionic 4.7应用程序中,尝试从Cordova摄像头插件上载图像 摄像头插件的输出是base64图像数据 this.camera.getPicture(options).then((imageData) => { // imageData is either a base64 encoded string or a file URI // If it's base64 (DATA_URL): const base64Image = 'data:image/jpeg;bas
this.camera.getPicture(options).then((imageData) => {
// imageData is either a base64 encoded string or a file URI
// If it's base64 (DATA_URL):
const base64Image = 'data:image/jpeg;base64,' + imageData;
this.uploadImage(url, base64Image )
}, (err) => {
// Handle error
});
我正在生成一个AWS S3预签名URL,以便在服务器端上传图像
e、 g
下面的代码没有给出任何错误,但上传的图像只是一个黑屏,而不是实际的图像
HTTP将图像放入S3(base64编码格式的可用图像)的正确方法是什么
uploadImage(url: string, imageData: any): Promise<any> {
const headers = new HttpHeaders({'Content-Type': 'image/jpeg;'});
return this.http.put(url, imageData, {headers: headers})
.pipe(
tap(data => console.log(JSON.stringify(data))),
catchError(this.handleError('uploadImage'))
).toPromise();
}
uploadImage(url:string,imageData:any):承诺{
const headers=新的HttpHeaders({'Content-Type':'image/jpeg;'});
返回this.http.put(url,imageData,{headers:headers})
.烟斗(
点击(data=>console.log(JSON.stringify(data)),
catchError(this.handleError('uploadImage'))
).toPromise();
}
通过选择二进制数据,可以使用邮递员进行上传。所以我继续用ionic 4和httpclient复制了相同的内容
步骤:
1.安装:npm安装缓冲区
2.更新tsconfig.app.json在“编译器选项”中包含类型“:[“节点”]。
3.在src/app/pollyfills.ts中添加(任意窗口).global=window
uploadImage(url: string, contentType: string, imageData: any): Promise<any> {
const headers = new HttpHeaders();
if (contentType === 'jpeg') {
headers.set('Content-Type', 'image/jpeg;');
} else if (contentType === 'png') {
headers.set('Content-Type', 'image/jpeg;');
}
const data = imageData.replace(/^data:image\/\w+;base64,/, '');
const buff = new Buffer(data, 'base64');
return this.http.put(url, buff.buffer, {headers: headers})
.pipe(
tap(data => console.log(JSON.stringify(data))),
catchError(this.handleError('uploadImage'))
).toPromise();
}
uploadImage(url:string,contentType:string,imageData:any):承诺{
const headers=新的HttpHeaders();
如果(contentType==='jpeg'){
headers.set('Content-Type','image/jpeg;');
}else if(contentType==='png'){
headers.set('Content-Type','image/jpeg;');
}
const data=imageData.replace(/^data:image\/\w+;base64,/,'');
const buff=新缓冲区(数据“base64”);
返回this.http.put(url,buff.buffer,{headers:headers})
.烟斗(
点击(data=>console.log(JSON.stringify(data)),
catchError(this.handleError('uploadImage'))
).toPromise();
}
如果将基本图像显示在imagw元素src中,它是否也会显示黑屏?否,它显示带有