Нужно уменьшать размер фотографии перед отправкой в базу данных. Мой текущий метод отправки.
private Uri ImageUriTwo;
private String DownloadImageUrlTwo;
private StorageReference magPhoto;
private static final int GALLERYPICK = 1;
private void OpenGallery() {
Intent galleryintent = new Intent();
galleryintent.setAction(Intent.ACTION_GET_CONTENT);
galleryintent.setType("image/*");
startActivityForResult(galleryintent, GALLERYPICK);
}
StorageReference filePath = magPhoto.child(ImageUriTwo.getLastPathSegment() + ".jpg");
final UploadTask uploadTask = filePath.putFile(ImageUriTwo);
uploadTask.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
String message = e.toString();
Toast.makeText(ShopName.this, "error" + message, Toast.LENGTH_SHORT).show();
progressDialog.dismiss();
}
}).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Toast.makeText(ShopName.this, "Изображение загружено", Toast.LENGTH_SHORT).show();
Task<Uri> uriTask = uploadTask.continueWithTask(new Continuation<UploadTask.TaskSnapshot, Task<Uri>>() {
@Override
public Task<Uri> then(@NonNull Task<UploadTask.TaskSnapshot> task) throws Exception {
if (!task.isSuccessful()) {
throw task.getException();
}
DownloadImageUrlTwo = filePath.getDownloadUrl().toString();
return filePath.getDownloadUrl();
}
}).addOnCompleteListener(new OnCompleteListener<Uri>() {
@Override
public void onComplete(@NonNull Task<Uri> task) {
if (task.isSuccessful()) {
DownloadImageUrlTwo = task.getResult().toString();
REGMAG();
}
}
});
}
});