I know there are several ways to replace getDownloadUrl() but it never works for me. Please help me if someone knows good method
So I'm trying to upload some postings with photos. Other things show up except for the images that I uploaded. And I think getDownloadUrl() is the problem.
public void onClick(View v) {
if (v.getId() == R.id.addphoto_btn_upload && photoUrl != null) {
Log.d("AddPhotoActivity", " upload button clicked");
File myFile = new File(photoUrl);
Uri contentUri = Uri.fromFile(myFile);
StorageReference storageReference = firebaseStorage.getReferenceFromUrl("gs://mystagram.appspot.com/").child("images").child(contentUri.getLastPathSegment());
UploadTask uploadTask = storageReference.putFile(contentUri);
uploadTask.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Toast.makeText(AddPhotoActivity.this, getString(R.string.upload_success), Toast.LENGTH_SHORT).show();
Task<Uri> uri = taskSnapshot.getStorage().getDownloadUrl();
DatabaseReference images = firebaseDatabase.getReference().child("images").push();
//Time
Date date = new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
ContentDTO contentDTO = new ContentDTO();
contentDTO.imageUrl = uri.toString();
contentDTO.explain = explain_editText.getText().toString();
contentDTO.userId = firebaseAuth.getCurrentUser().getEmail();
contentDTO.timeStamp = Long.valueOf(simpleDateFormat.format(date));
images.setValue(contentDTO);
AddPhotoActivity.this.finish();
}
});
How can I change this?