Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can`t send image using Chat21 SDK. #47

Open
vikas-jain-plutus opened this issue Jun 30, 2020 · 2 comments
Open

Can`t send image using Chat21 SDK. #47

vikas-jain-plutus opened this issue Jun 30, 2020 · 2 comments

Comments

@vikas-jain-plutus
Copy link

vikas-jain-plutus commented Jun 30, 2020

Facing issue while Image uploading.

@vikas-jain-plutus
Copy link
Author

// 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
Copy link
Author

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");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant