chat21 / chat21-android-sdk

Android Chat SDK built on Firebase
http://www.chat21.org
MIT License
233 stars 98 forks source link

crashed when share an image #40

Open vandanabpatel opened 4 years ago

vandanabpatel commented 4 years ago

when i try to send image app got crashed

shashankshahplutus commented 4 years ago

@vandanabpatel did you resolved the issue? if so share an idea behind it ?

vikas-jain-plutus commented 4 years ago

private static void performUpload(Uri file, final String type, final OnUploadedCallback callback) { // public storage folder StorageReference storageReference; if (StringUtils.isValid(ChatManager.Configuration.storageBucket)) { storageReference = FirebaseStorage.getInstance() .getReferenceFromUrl(ChatManager.Configuration.storageBucket) .child("public"); } else { storageReference = FirebaseStorage.getInstance() .getReference() .child("public"); }

    // random uid.
    // this is used to generate an unique folder in which
    // upload the file to preserve the filename
    final String uuid = UUID.randomUUID().toString();

    // upload to /public/images/uuid/file.ext
    StorageReference riversRef = storageReference.child(type.toString() + "/" + uuid + "/" +
            file.getLastPathSegment());
    Log.d(TAG, "riversRef ==" + riversRef);

    UploadTask uploadTask = riversRef.putFile(file);

    // Register observers to listen for when the download is done or if it fails
    uploadTask.addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception exception) {
            // Handle unsuccessful uploads
            Log.e(TAG, "addOnFailureListener.onFailure: " + exception.getMessage());

            callback.onUploadFailed(exception);
        }
    }).addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
        @Override
        public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
            double progress = (100.0 * taskSnapshot.getBytesTransferred()) / taskSnapshot.getTotalByteCount();
            Log.d(TAG, "Upload is " + progress + "% done");
            int currentProgress = (int) progress;
            callback.onProgress(currentProgress);
        }
    }).addOnPausedListener(new OnPausedListener<UploadTask.TaskSnapshot>() {
        @Override
        public void onPaused(UploadTask.TaskSnapshot taskSnapshot) {
            System.out.println("Upload is paused");
        }
    }).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
        @Override
        public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
            // taskSnapshot.getMetadata() contains file metadata such as size,
            // content-type, and download URL.
            Uri downloadUrl = taskSnapshot.getUploadSessionUri();
            Log.d(TAG, "addOnFailureListener.onSuccess - downloadUrl: " + downloadUrl);

            callback.onUploadSuccess(uuid, downloadUrl, type);
        }
    });
}

I am getting an issue while uploading the image. Can anyone help me on this?