_pickCameraPrepare = () => {
this._pickCameraPermission()
}
_pickCameraPermission = async ()=>{
const { status } = await Permissions.getAsync(Permissions.CAMERA)
const { status: statusRoll} = await Permissions.getAsync(Permissions.CAMERA_ROLL)
if (status === 'granted'&& statusRoll === 'granted') {
this._pickCamera();
} else {
alert('permission denied');
}
}
_pickCamera = async () => {
let result = await ImagePicker.launchCameraAsync({
allowsEditing: true,
aspect: [4, 3],
});
console.log(result);
if (!result.cancelled) {
this.uploadImage(result.uri, "camera-image")
this.setState({ image: result.uri });
}
};
_pickImagePrepare = () => {
if (Platform.OS === ‘ios’) {
this._pickImagePermission()
} else {
this._pickImage();
}
}
_pickImagePermission = async () => {
const { status } = await Permissions.getAsync(Permissions.CAMERA_ROLL)
if (status === ‘granted’) {
this._pickImage();
} else {
alert(‘permission denied’);
}
}
_pickImage = async () => {
let result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ‘Images’,
allowsEditing: true,
aspect: [4, 3],
});
console.log(result);
if (!result.cancelled) {
this.uploadImage(result.uri, "gallery-image")
this.setState({ image: result.uri });
}
}
uploadImage = async (uri, imageName) => {
var metadata = {
contentType: ‘image/jpeg’,
}
const response = await fetch(uri);
const blob = await response.blob();
var ref = firebase.storage().ref().child("images/" + imageName);
return ref.put(blob, metadata);
}
Basically, I tried to use the above codes to upload image to firebase. It works in the sense that can upload, but, it detects as either image of 0 byte or application/octet-stream format with 0 byte. Please help!
The error in image preview also persist when i play around with the settings Do help and thanks (: