In my case, I tried with the following code on Android Java but I am unable to get the download URL for imageURL; Can you please help me to get the download URL in firebase?
ActivityResultLauncher<String> mGetContent = registerForActivityResult(new ActivityResultContracts.GetContent(),
new ActivityResultCallback<Uri>() {
@Override
public void onActivityResult(Uri uri) {
//You are provided with uri of the image . Take this uri and assign it to Picasso
//Intent openGalleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
mImageUri = uri.normalizeScheme();
Picasso.get().load(mImageUri).fit().into(productImage);
}
});
upload File code
private void uploadFile(){
if(mImageUri != null){
StorageReference fileReference = storageReference.child(System.currentTimeMillis()+ "."+ getFileExtension(mImageUri));
storageTask = fileReference.putFile(mImageUri)
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Toast.makeText(Add_Product.this,"Product Added Successfully",Toast.LENGTH_LONG).show();
AdminProductModel addProduct = new AdminProductModel(productName.getText().toString().trim(),
//fileReference.getDownloadUrl().toString(),
//taskSnapshot.getMetadata().getReference().getDownloadUrl().toString(),
taskSnapshot.getUploadSessionUri().toString(),
unitPrice.getText().toString().trim(),
description.getText().toString().trim(),
liter.getText().toString().trim());
String uploadId = databaseReference.push().getKey();
databaseReference.child(uploadId).setValue(addProduct);
}
})
I used these ways to get the URL but doesn't work
taskSnapshot.getMetadata().getReference().getDownloadUrl().toString()
fileReference.getDownloadUrl().toString()
taskSnapshot.getStorage().getDownloadUrl().toString()