chat21-android-sdk icon indicating copy to clipboard operation
chat21-android-sdk copied to clipboard

Can`t send image using Chat21 SDK.

Open vikas-jain-plutus opened this issue 4 years ago • 2 comments

Facing issue while Image uploading.

vikas-jain-plutus avatar Jun 30 '20 15:06 vikas-jain-plutus

// execute the upload 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);
        }
    });
}

vikas-jain-plutus avatar Jul 02 '20 11:07 vikas-jain-plutus

When I am using implementation 'com.google.firebase:firebase-storage:11.8.0' App gets crashed on this line with below error... storageReference = FirebaseStorage.getInstance() .getReference() .child("public");

vikas-jain-plutus avatar Jul 02 '20 11:07 vikas-jain-plutus