Image Picker not working

_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 :frowning: Do help and thanks (:

1 Like

just to include, it doesn’t work on android. Image doesn’t even upload

Hey @fritopower,

Just want to try and seek some clarification here. Is the ImagePicker working properly (as in can you display the image via an Image component in app)? At first glance, it seems like this might be a firebase/blob issue but want to make sure.

Cheers,
Adam

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.