i want to upload images in firebase from the four boxes and getdownload url for each
我正在编写一个应用来测试Firebase,用户可以在其中上传带有图片的产品。我在上传时遇到问题,因为图片已存储,但未链接到产品(图像数组未传递?),并且LeakCanary发出内存不足错误的信号。感谢所有帮助和投入。
这是我的产品型号
final ProgressDialog mDialog = new ProgressDialog(this);
mDialog.setMessage("Uploading....");
mDialog.show();
newFood = new Food();
final String imageName = UUID.randomUUID().toString();
final StorageReference imageFolder = storageReference.child("images/" + Common.imgFront.getLastPathSegment());
final StorageReference imageFolder1 = storageReference.child("images/" + Common.imgBack.getLastPathSegment());
final StorageReference imageFolder2 = storageReference.child("images/" + Common.imgRight.getLastPathSegment());
final StorageReference imageFolder3 = storageReference.child("images/" + Common.imgLeft.getLastPathSegment());
imageFolder.putFile(saveUri)
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
// Toast.makeText(FileUpload.this, "Uploaded !!!", Toast.LENGTH_SHORT).show();
imageFolder.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
newFood.setName(carName.getText().toString());
newFood.setEngine(carEngine.getText().toString());
newFood.setPrice(carPrice.getText().toString());
newFood.setTransmission(carTransmission.getText().toString());
newFood.setCondition(carCondition.getText().toString());
newFood.setOther(otherDescription.getText().toString());
newFood.setDiscount(carDiscount.getText().toString());
newFood.setMenuId(categoryId);
newFood.setImagefront(uri.toString());
}
});
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
mDialog.dismiss();
Toast.makeText(FileUpload.this, "" + e.getMessage(), Toast.LENGTH_SHORT).show();
}
});
imageFolder1.putFile(saveUri)
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
// Toast.makeText(FileUpload.this, "Uploaded !!!", Toast.LENGTH_SHORT).show();
imageFolder.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
newFood.setImageback(uri.toString());
}
});
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
mDialog.dismiss();
Toast.makeText(FileUpload.this, "" + e.getMessage(), Toast.LENGTH_SHORT).show();
}
});
imageFolder2.putFile(saveUri)
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
// Toast.makeText(FileUpload.this, "Uploaded !!!", Toast.LENGTH_SHORT).show();
imageFolder.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
newFood.setImageright(uri.toString());
}
});
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
mDialog.dismiss();
Toast.makeText(FileUpload.this, "" + e.getMessage(), Toast.LENGTH_SHORT).show();
}
});
imageFolder3.putFile(saveUri)
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
mDialog.dismiss();
Toast.makeText(FileUpload.this, "Uploaded !!!", Toast.LENGTH_SHORT).show();
imageFolder.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
newFood.setImageleft(uri.toString());
if (newFood !=null)
{
foods.push().setValue(newFood);
Snackbar.make(rootLayout, "New Car "+newFood.getName()+ " was added",Snackbar.LENGTH_SHORT)
.show();
}
}
});
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
mDialog.dismiss();
Toast.makeText(FileUpload.this, "" + e.getMessage(), Toast.LENGTH_SHORT).show();
}
});
答案 0 :(得分:0)
没有使用Firebase存储同时上传或下载多个图像的API。 You can check a workaround on this other stack overflow question