Giter Club home page Giter Club logo

Comments (21)

ankode avatar ankode commented on August 23, 2024 19

Fixed

replace task.getResult().getMetadata().getDownloadUrl() by task.getResult().getStorage()().getDownloadUrl()

Reason is mentioned on StackOverflow:
The getDownloadUrl() and getDownloadUrls() methods of the StorageMetadata class are now deprecated. Use getDownloadUrl() from StorageReference instead.

from codelab-friendlychat-android.

kevinkoech avatar kevinkoech commented on August 23, 2024 12

I faced the same problem but I got the answer

Just add .getStorage() infront of .getDownloadurl

to be like this below

.getStorage().getDownloadUrl 

LEAVE EVERYTHING IN THAT LINE DONT ALTER JUST ADD .getStorage()

from codelab-friendlychat-android.

luongchung avatar luongchung commented on August 23, 2024 1

Fixed

replace task.getResult().getMetadata().getDownloadUrl() by task.getResult().getStorage()().getDownloadUrl()

Reason is mentioned on StackOverflow:
The getDownloadUrl() and getDownloadUrls() methods of the StorageMetadata class are now deprecated. Use getDownloadUrl() from StorageReference instead.

Thanks Bro !

from codelab-friendlychat-android.

morganchen12 avatar morganchen12 commented on August 23, 2024

Can you share the error?

from codelab-friendlychat-android.

ankode avatar ankode commented on August 23, 2024

@morganchen12

I am also getting the same error on Android Studio 3.1.2

In method putImageInStorage of MainActivity

    @Override
               public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {
                   if (task.isSuccessful()) {
                       FriendlyMessage friendlyMessage =
                               new FriendlyMessage(null, mUsername, mPhotoUrl,
                                       task.getResult().getMetadata().getDownloadUrl()
                                               .toString());
                       mFirebaseDatabaseReference.child(MESSAGES_CHILD).child(key)
                               .setValue(friendlyMessage);
                   } else {
                       Log.w(TAG, "Image upload task was not successful.",
                               task.getException());
                   }
               }

getDownloadUrl() of task.getResult().getMetadata().getDownloadUrl() is giving error "cannot resolve method 'getDownloadUrl()' "

from codelab-friendlychat-android.

sumitchawandia avatar sumitchawandia commented on August 23, 2024

Thanks @ankode it's worked.

from codelab-friendlychat-android.

ynroot avatar ynroot commented on August 23, 2024

you can find the solution here: https://stackoverflow.com/a/51076403/3135287

from codelab-friendlychat-android.

kevinkoech avatar kevinkoech commented on August 23, 2024

I had tried to help people on stackoverflow to answer this but they raised my reputation higher so I cant answer there...too bad

from codelab-friendlychat-android.

dankhalif avatar dankhalif commented on August 23, 2024

I faced the same problem but I got the answer

Just add .getStorage() infront of .getDownloadurl

to be like this below

.getStorage().getDownloadUrl 

LEAVE EVERYTHING IN THAT LINE DONT ALTER JUST ADD .getStorage()

this code saved me thank you so much

from codelab-friendlychat-android.

mohannmpl avatar mohannmpl commented on August 23, 2024

Just replace from taskSnapshot.getDownloadUrl().toString() to mImageUri.toString() it works thanks

or use
taskSnapshot.getMetadata().getReference().getDownloadUrl().toString()

from codelab-friendlychat-android.

Sachayanthan-V avatar Sachayanthan-V commented on August 23, 2024

I want
task.getResult().getDownloadUrl().toString() -----> this statement

task.getResult().getStorage().getDownloadUrl().toString() -----> this is works and doesn't shows any error but in app I try to open its crashes.

So, What can I do friends.?

from codelab-friendlychat-android.

abdou333 avatar abdou333 commented on August 23, 2024

i have a problem , after a long search i din't a suitable solution
ca not resolve getdonwloadUrl()
please help me
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@OverRide
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
// Upload succeeded
Log.d(TAG, "OnSuccessListener");

                Uri downloadUri = taskSnapshot.getMetadata().getDownloadUrl();
                Log.d(TAG, "downloadUri: " + downloadUri);

                pdfsize = taskSnapshot.getMetadata().getSizeBytes();
                pdfsize = pdfsize/1048576;
                Log.d(TAG, "onSuccess: fileSize"+pdfsize);


                uploaddate = FindCurrentDate();




                Toast.makeText(MyUploadService.this, getString(R.string.upload_success), Toast.LENGTH_LONG).show();

                uploadOnDB(downloadUri.toString(), pdfref.getName());

                broadcastUploadFinished(downloadUri, fileUri);
                showUploadFinishedNotification(pdfname, downloadUri, fileUri);
                taskCompleted();

            }
        })

from codelab-friendlychat-android.

coder63480 avatar coder63480 commented on August 23, 2024

my code isn´t working can you help me?

here is my code:

private void saveToStories() {

    final DatabaseReference userStoryDb = FirebaseDatabase.getInstance().getReference().child("users").child(Uid).child("story");
    final String key = userStoryDb.push().getKey();

    StorageReference filePath = FirebaseStorage.getInstance().getReference().child("captures").child(key);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    rotateBitmap.compress(Bitmap.CompressFormat.JPEG, 20, baos);
    byte[] dataToUpload = baos.toByteArray();
    UploadTask uploadTask = filePath.putBytes(dataToUpload);

    uploadTask.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
        @Override
        public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
            Uri imageUrl = taskSnapshot.getDownloadUrl();

            Long currentTimestamp = System.currentTimeMillis();
            Long endTimestamp = currentTimestamp + (24*60*60*1000);

            Map<String, Object> mapToUpload = new HashMap<>();
            mapToUpload.put("imageUrl", imageUrl.toString());
            mapToUpload.put("timestampBeg", currentTimestamp);
            mapToUpload.put("timestampEnd", endTimestamp);

            userStoryDb.child(key).setValue(mapToUpload);

            finish();
            return;
        }
    });

    uploadTask.addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
            finish();
            return;
        }
    });
}

from codelab-friendlychat-android.

burhanuddinhamzabhai avatar burhanuddinhamzabhai commented on August 23, 2024

I faced the same problem but I got the answer
Just add .getStorage() infront of .getDownloadurl
to be like this below

.getStorage().getDownloadUrl 

LEAVE EVERYTHING IN THAT LINE DONT ALTER JUST ADD .getStorage()

this code saved me thank you so much

it is not giving valid URL for me

from codelab-friendlychat-android.

sonali822 avatar sonali822 commented on August 23, 2024

val downloadUrl = taskSnapshot.downloadUrl
this taskSnapshot.downloadUrl shows me error please anyone can help??
my image is not saved in firebase only this error in my code please help

from codelab-friendlychat-android.

burhanuddinhamzabhai avatar burhanuddinhamzabhai commented on August 23, 2024

i did this instead and it resolved the problem for me
Task task = taskSnapshot.getMetadata().getReference().getDownloadUrl();
task.addOnSuccessListener(new OnSuccessListener() {
@OverRide
public void onSuccess(Uri uri) {
String url = uri.toString();
}

first i uploaded the image to storage and then i fetch the url using this method to place it in the database.

from codelab-friendlychat-android.

rajathbagre avatar rajathbagre commented on August 23, 2024

taskSnapshot.getMetadata().getReference().getDownloadUrl().toString() use this it worked for me

from codelab-friendlychat-android.

Azimeraw avatar Azimeraw commented on August 23, 2024

taskSnapshot.getMetadata().getReference().getDownloadUrl().toString() and also use taskSnapshot.getStorage().getDownloadUrl().toString() this it is not worked for me could you help me

from codelab-friendlychat-android.

burhanuddinhamzabhai avatar burhanuddinhamzabhai commented on August 23, 2024

taskSnapshot.getMetadata().getReference().getDownloadUrl().toString() and also use taskSnapshot.getStorage().getDownloadUrl().toString() this it is not worked for me could you help me

Task task = taskSnapshot.getMetadata().getReference().getDownloadUrl();
task.addOnSuccessListener(new OnSuccessListener() {
@OverRide
public void onSuccess(Uri uri) {
String url = uri.toString();
}
try this

from codelab-friendlychat-android.

het-desai avatar het-desai commented on August 23, 2024

This work very well and easy way to write code for uploading and downloading image file.

Uri selectedImageUri = data.getData();
            final StorageReference photoRef = mChatStorageReference.child(selectedImageUri.getLastPathSegment());

            //This line of code is actually upload photo to database storage
            photoRef.putFile(selectedImageUri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                @Override
                public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                    Toast.makeText(MainActivity.this, "Image Successfully uploaded", Toast.LENGTH_SHORT).show();
                    photoRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
                        @Override
                        public void onSuccess(Uri uri) {
                            FriendlyMessage friendlyMessage = new FriendlyMessage(null, mUsername, uri.toString());
                            mMessagesDatabaseReference.push().setValue(friendlyMessage);
                        }
                    });
                }
            }).addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    Toast.makeText(MainActivity.this, "Image Fail to upload", Toast.LENGTH_SHORT).show();
                }
            });

from codelab-friendlychat-android.

Azimeraw avatar Azimeraw commented on August 23, 2024

from codelab-friendlychat-android.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.