我尝试在Firebase存储中上传多个图像,然后将图像的下载URL存储到Firebase实时数据库中。当图像大小在15Mb左右时,我会遇到问题。问题在于数据库不存储较大图像的URL。
目前,我以字节数组的形式上传图像。压缩后使用JPEG图像格式。
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();
}
}