So i'm trying to get the user to pick an image from their photo gallery then upload it to Firebase Storage...so far my code looks as follows:
@Override
protected void onActivityResult(int requestCode,int resultcode, Intent data){
super.onActivityResult(requestCode,resultcode,data);
if(requestCode == REQUEST_IMAGE_CAPTURE && resultcode == RESULT_OK) {
final Uri uri = data.getData();
if (uri != null){
Bitmap bmp = null;
try {
bmp = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
} catch (IOException e){
e.printStackTrace();
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 25, baos);
byte[] fileInBytes = baos.toByteArray();
bmp.recycle();
FirebaseAuth auth = FirebaseAuth.getInstance();
FirebaseStorage storage = FirebaseStorage.getInstance();
String imageString = "";
if(clickPhoto ==1){imageString = "Image 1"; }
else if(clickPhoto ==2){imageString = "Image 2"; }
else if (clickPhoto ==3){imageString = "Image 3"; }
else if (clickPhoto ==4){imageString = "Image 4"; }
final StorageReference storageReference = storage.getReference().child("Images").child("users").child(auth.getCurrentUser().getUid()).child(imageString);
storageReference.putBytes(fileInBytes).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
storageReference.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
String downloadUrl = uri.toString();
String urlString ="";
if(clickPhoto ==1){ urlString = "photo1URI";}
if(clickPhoto ==2){ urlString = "photo2URI";}
else if (clickPhoto ==3){ urlString = "photo3URI";}
else if (clickPhoto ==4){urlString = "photo4URI";}
toMap.put(urlString, downloadUrl);
updatedb();
toMap.clear();
Log.d("uriii",downloadUrl);}
});
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.d("UploadFailure",e.getMessage());
}
});
}
else {
Toast.makeText(this,"Didn't work",Toast.LENGTH_LONG).show();
}
}
}
My problem is that the image that is uploaded changes orientation...seeminly at random....how do i maintain orientation? I've looked at Exif interface but can't see an answer for uploading it as a ByteArrayOutputStream?
Any help would be appreciated.