I'm trying to upload and download images from Firabase Database which has an URL link to Firebase Storage. The problem is that the strange URL is being saved to database (see the link at the bottom). What should I do to obtain a normal URL that I will be able to use do downloand the image into my Android app? Thank you in advance!
Here I post some code I use:
Upload to Firebase DataBase and Storage:
mStorageRef = FirebaseStorage.getInstance().getReference();
mDataBaseRef = FirebaseDatabase.getInstance().getReference();
if (mImageUri != null)
{
final StorageReference fileReference = mStorageRef.child(nameimage + "." + getFileExtension(mImageUri));
fileReference.putFile(mImageUri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Toast.makeText(AddAdvertisement.this, "Upload successful!", Toast.LENGTH_LONG).show();
Upload upload = new Upload(et_localization, taskSnapshot.getUploadSessionUri().toString());
String uploadId = mDataBaseRef.push().getKey();
mDataBaseRef.child(uploadId).setValue(upload);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(AddAdvertisement.this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
});
And download from Firebase:
databaseReference = FirebaseDatabase.getInstance().getReference();
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot postSnapshot : dataSnapshot.getChildren())
{
Upload upload = postSnapshot.getValue(Upload.class);
mUploads.add(upload);
}
mAdapter = new AdverisementAdapter(getContext(),mUploads);
mrecyclerView.setAdapter(mAdapter);
}
and Picasso to retreive image:
@Override
public void onBindViewHolder(@NonNull ImageViewHolder imageViewHolder, int i) {
Upload uploadCurrent = mUploads.get(i);
imageViewHolder.textViewName.setText(uploadCurrent.getName());
Picasso.get().load(uploadCurrent.getUrl()).into(imageViewHolder.imageView);
}
Picasso work fine, beacuse except form an image I also get from Firebase string with the name, which is downloaded appropriately. So, the problem I think it's just with this wrong url:
When I try to entered this link, I receive this kind of error:
Invalid request. X-Goog-Upload-Command header is missing.