javascript - 从相机胶卷中选择图像和 gif
问题描述
我正在使用 Angular 和 Firebase 构建一个 Ionic 应用程序。
我希望能够将图像和 gif 上传到我的 firebase 数据库,但我只能开始image
工作。另外,我不想要视频。
我的代码如下:
takePhoto(sourceType:number) {
const options: CameraOptions = {
quality: 40,
destinationType: this.camera.DestinationType.DATA_URL,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE,
correctOrientation: true,
sourceType:sourceType,
}
this.camera.getPicture(options).then((imageData) => {
let base64Image = 'data:image/jpeg;base64,' + imageData;
this.uploadToStorage(base64Image);
}, (err) => {
// Handle error
});
}
uploadToStorage(src) {
this.uploadProgress = true;
let storageRef = firebase.storage().ref();
// Create a timestamp as filename
this.imageFileName = Math.floor(Date.now() / 1000) + "_" + this.userData.uid;
// Create a reference to 'images/todays-date.jpg'
const imageRef = storageRef.child('posts/'+this.imageFileName+'.jpg');
imageRef.putString(src, firebase.storage.StringFormat.DATA_URL).then((snapshot)=> {
snapshot.ref.getDownloadURL().then(downloadURL => {
this.imageURL = downloadURL;
this.uploadProgress = false;
this.uploadSuccess = true;
console.log(this.imageURL)
this.logEvent("Uploaded Image");
});
}, (err) => {
console.log(err)
});
}
但这仅允许静止图像。根据Ionic Camera的文档,
您可以更改mediaType: this.camera.MediaType.PICTURE
为,mediaType: this.camera.MediaType.ALLMEDIA
但这对我不起作用。当我在我的电脑上测试时它可以工作,但在 iOS 或 Android 上不行。
有什么想法可以让我选择图像和 GIF 吗?谢谢!
解决方案
photos ;
OpenGallery(){
console.log("taktit");
const options: CameraOptions = {
quality: 100,
destinationType: this.camera.DestinationType.DATA_URL,
sourceType: this.camera.PictureSourceType.SAVEDPHOTOALBUM
}
this.camera.getPicture(options).then((imageData) => {
// imageData is either a base64 encoded string or a file URI
// If it's base64:
console.log("taktit");
let base64Image = 'data:image/jpeg;base64,' + imageData;
this.photos.push(base64Image);
this.photos.reverse();
}, (err) => {
// Handle error
}); else { }
}
- 现在您可以将您的对象照片上传到您的火力基地
推荐阅读
- c - 释放结构指针的特定元素 - C
- javascript - 使用js更改单选按钮时更改单选按钮的值和id
- javascript - 使用 Rxjs 进行优化
- php - 强制 WooCommerce 电子邮件模板
- android - Android 7 及更高版本的通话录音
- c# - C# ClosedXML 表格主题列表
- ruby - Ruby gem 以获得更好/真实的代码覆盖率(多次测试测试用例)
- operating-system - 多核线程处理
- java - 如何在邮递员中请求 Rest API eclipse 服务?
- node.js - 无法在 AWS S3 上使用 Node.js/axios 上传图像