Reputation: 11
I am developing an android application which includes photos and videos upload/downloads to firebase storage. I am very happy with the firebase features, but uploading/downloading image and video taking little more time, even though I am on the high-speed internet.
Upload and Download of image and videos work perfectly, But I can't expect the slowness from a Google-backed platform. I am compressing the image before upload even though, the time taken is more. say for eg. I uploaded 7Mb size image on WhatsApp profile pic it will be done in max 5-6 seconds. But the same image upload will take more than 60 seconds in my android app.
Guys, if you have any better solutions or any implementation from your end Please share it.
Regards, Srini
Upvotes: 0
Views: 5388
Reputation: 1008
It's all about media compression. You can also upload image, video and other media file same as WhatsApp by compressing you media. after compression check speed of firebase for upload and download. you will also feel the speed of it.
Here is the tools for compression
and many more. I'm using this two libs for compress video and image files.
Use firebase upload this way.
File file =new File(mediaPath);
if(file.exists()) {
UploadTask uploadTask = riversRef.putFile(Uri.fromFile(file),metadata);
Task<Uri> urlTask = uploadTask.continueWithTask(new Continuation<UploadTask.TaskSnapshot, Task<Uri>>() {
@Override
public Task<Uri> then(@NonNull Task<UploadTask.TaskSnapshot> task) throws Exception {
if (!task.isSuccessful()) {
throw task.getException();
}
// Continue with the task to get the download URL
return riversRef.getDownloadUrl();
}
}).addOnCompleteListener(task -> {
if (task.isSuccessful()) {
Uri downloadUri = task.getResult();
getUploadedMediaPath.getUploadedFileUrl(downloadUri.toString());
}
});
}
Upvotes: 1
Reputation: 681
Have you tried check out WebP and WebM for photo and video?
It's a format developed by some team at Google in aiming to reduce file sizes to minimal as it be without altering the quality of the files massively. The results are quiet good compares to other format of images and videos. WebP also support encoder and decoder.
Check out the tools here WebP :
Just download the tool and have it in your working folder, invoke command prompt and run
cwebp -q int fileName.jpg -o fileName.webp
and see the result.
Check out the tools for WebM:
Upvotes: 0
Reputation: 456
try this
// Get the data from an ImageView as bytes
Bitmap bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
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, etc.
// ...
}
});
Upvotes: 0