I am performing upload data with the image using a firebase real-time database. But the method getDownloadUrl() is giving me an error. I have created a schema named StorageSchema. Actually, I am sending the data by making StorageSchema constructor but when I try to take the Image URL then it gives the error.
private void upload_product() {
if(mImageUri != null){
final StorageReference fileReference =
mStorageRef.child(System.currentTimeMillis()
+"."+getFileExtension(mImageUri));
uploadProgressBar.setVisibility(View.VISIBLE);
uploadProgressBar.setIndeterminate(true);
mUploadTask = fileReference.putFile(mImageUri)
.addOnSuccessListener(new
OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
uploadProgressBar.setVisibility(View.VISIBLE);
uploadProgressBar.setIndeterminate(false);
uploadProgressBar.setProgress(0);
}
},500);
Toast.makeText(Add_Item.this, "Product Upload Successful",
Toast.LENGTH_SHORT).show();
StorageSchema upload = new StorageSchema(
productname.getText().toString().trim(),
productdescription.getText().toString(),
//the problem is here in getDownloadUrl() method
taskSnapshot.getDownloadUrl().toString());
String uploadId = mDatabaseRef.push().getKey();
mDatabaseRef.child(uploadId).setValue(upload);
uploadProgressBar.setVisibility(View.INVISIBLE);
}
});
}
}
//starting the StorageSchema class having the schema
public class StorageSchema {
private String productname;
private String productdescription;
private String imageUrl;
private int rate;
private String unit;
private int position;
private String key;
public StorageSchema(){
//empty constructor needed
}
public StorageSchema(int position){
this.position=position;
}
public StorageSchema(String productname, String productdescription, String
imageUrl, int rate, String unit){
if(productname.trim().equals("")){
productname = "No Name";
}
this.productname = productname;
this.productdescription = productdescription;
this.imageUrl = imageUrl;
this.rate = rate;
this.unit = unit;
}
I want to use getDownloadUrl(), if now not supported due to latest versions then how could I get the image URL.