Created
September 15, 2016 15:40
-
-
Save mogeta/d8abda24799d407673af3c7f908e927f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//upload image for firebase storage | |
private void updateImage(ImageView imageView){ | |
// Create a storage reference from our app | |
FirebaseStorage storage = FirebaseStorage.getInstance(); | |
StorageReference storageRef = storage.getReferenceFromUrl("<your-storage-url>"); | |
String uuid = UUID.randomUUID().toString(); | |
StorageReference mountainsRef = storageRef.child(uuid + ".jpg"); | |
imageView.setDrawingCacheEnabled(true); | |
imageView.buildDrawingCache(); | |
Bitmap bitmap = imageView.getDrawingCache(); | |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | |
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos); | |
byte[] data = baos.toByteArray(); | |
UploadTask uploadTask = mountainsRef.putBytes(data); | |
uploadTask.addOnFailureListener(new OnFailureListener() { | |
@Override | |
public void onFailure(@NonNull Exception exception) { | |
// Handle unsuccessful uploads | |
} | |
}).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() { | |
@Override | |
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { | |
// taskSnapshot.getMetadata() contains file metadata such as size, content-type, and download URL. | |
Uri downloadUrl = taskSnapshot.getDownloadUrl(); | |
AddNewImageURL(downloadUrl); | |
Log.e("info", downloadUrl.toString()); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment