0

I am trying to upload multiple images in firebase storage, then I stored the download URLs of images into firebase realtime database. I face the problem when image size is big something around 15Mb. The problem is that the database doesn't store the url of bigger images.

Currently I am uploading images as array of bytes.I use JPEG image format after compression.

private void uploadFile() {

    int j;



        for (j = 0; j < mGallery.getChildCount(); j++) {

            StorageReference storageReference = mStorageRef.child(System.currentTimeMillis() + j + ".jpg");
            mUploadTask = storageReference.putBytes(uploadImageBytes[j]);

            final int Finalj = j;
            mUploadTask.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                @Override
                public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                    Task<Uri> urlTask = taskSnapshot.getStorage().getDownloadUrl();
                    while (!urlTask.isSuccessful()) ;
                    Uri downloadUri = urlTask.getResult();
                    String download_url = String.valueOf(downloadUri);
                    Log.e(TAG, "onSuccess: " + Finalj + " " + download_url);
                    setDownloadUrlArray(download_url, Finalj);
                    Toast.makeText(CameraAndPrizeFrag.this, "Upload Successful", Toast.LENGTH_SHORT).show();
                    uploadDelay(Finalj);
                }


            });

} }

private void uploadDelay(int j) {

    String[] tempUrls = getDownloadUrlArray();

    Log.e(TAG, "uploadDelay: 1" + tempUrls[0] + tempUrls[1]);
    Log.e(TAG, "uploadDelay: " + currentUser);
    Toast.makeText(this, "Upload done temp", Toast.LENGTH_SHORT).show();
    if (j == (mGallery.getChildCount() - 1) ) {
        int price = Integer.parseInt(mPrizeInfo.getText().toString());
        Intent i = getIntent();
        nameOfBook = i.getStringExtra("ItemName");
        author = i.getStringExtra("ItemAuthor");
        publication = i.getStringExtra("ItemPublication");
        descriptionOfBook = i.getStringExtra("ItemDescription");
        UploadData uploadData = new UploadData(currentUser, nameOfBook.trim(), tempUrls, price, author, publication, descriptionOfBook);

        String uploadId = mDataRef.push().getKey();

        mDataRef.child(uploadId).setValue(uploadData);
        Toast.makeText(this, "Upload done", Toast.LENGTH_SHORT).show();
    }


}
Markus Kauppinen
  • 3,025
  • 4
  • 20
  • 30
  • You can compress image and then send. – Chirag Savsani Jun 20 '19 at 11:02
  • can you please check the rule you have given for file size in firebase? – PJain Jun 20 '19 at 12:14
  • This `while (!urlTask.isSuccessful()) ;` is a bad idea. You should add a success listener as shown here https://stackoverflow.com/questions/51056397/how-to-use-getdownloadurl-in-recent-versions/51064689#51064689 and in the documentation here: https://firebase.google.com/docs/storage/android/upload-files#get_a_download_url and here https://firebase.google.com/docs/storage/android/download-files#download_data_via_url – Frank van Puffelen Jun 20 '19 at 14:14

0 Answers0