我想在Firebase中上载图像列表,但在Firebase中,成功侦听器未在OnSuccessListener上添加图像列表。
已尝试我在工作的add onSuccessListener类之外添加了字符串值,并且尝试记录它也起作用的url。但是它没有在OnSuccessListener的arrayList中添加字符串值。谢谢您的帮助。
主要代码
public void UploadImage() {
if (isUserSelected != null) {
progressDialog.setTitle("Image is Uploading...");
Log.d(TAG, "UploadImage: uploading");
progressDialog.show();
Log.d(TAG, "UploadImage: after progress bar");
for (int i = 0; i < multipleFileUploads.size(); i++) {
Log.d(TAG, "UploadImage: " + i);
final StorageReference storageReference2 = storageReference.child(System.currentTimeMillis() + "." + GetFileExtension(multipleFileUploads.get(i)));
storageReference2.putFile(multipleFileUploads.get(i))
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Log.d(TAG, "onSuccess: ");
progressDialog.dismiss();
Toast.makeText(getApplicationContext(), "Image Uploaded Successfully ", Toast.LENGTH_LONG).show();
storageReference2.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
Log.d(TAG, "onSuccess: uri " + uri.toString());
imagelist.add(uri.toString());
}
});
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.d(TAG, "onFailure: " + e.getMessage());
}
}).addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
@Override
public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
Log.d(TAG, "onProgress: " + taskSnapshot.getBytesTransferred());
Log.d(TAG, "onProgress: " + taskSnapshot.getTotalByteCount());
}
}).addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
@Override
public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {
Log.d(TAG, "onComplete: " + task.getException());
}
});
}
imageList.add("custom list");
uploadinfo imageUploadInfo = new uploadinfo(txtdata.getText().toString(), txtData1.getText().toString(), imageList.toString());
String ImageUploadId = databaseReference.push().getKey();
databaseReference.child(ImageUploadId).setValue(imageUploadInfo);
} else {
Toast.makeText(uploadimg1.this, "Please Select Image or Add Image Name", Toast.LENGTH_LONG).show();
}
Firebase的POJO代码
public class uploadinfo {
public String imageName;
public String imageName1;
public String imageListString;
public uploadinfo(String imageName, String imageName1, String imageListString) {
this.imageName = imageName;
this.imageName1 = imageName1;
this.imageListString = imageListString;
}
public String getImageName() {
return imageName;
}
public void setImageName(String imageName) {
this.imageName = imageName;
}
public String getImageName1() {
return imageName1;
}
public void setImageName1(String imageName1) {
this.imageName1 = imageName1;
}
public String getImageListString() {
return imageListString;
}
public void setImageListString(String imageListString) {
this.imageListString = imageListString;
}
}
我想在firebase中上传图片列表,但是在firebase上传成功侦听器中没有在OnSuccessListener上添加图片列表。我尝试在add onSuccessListener之外添加字符串值...
问题可能出在您的模型中。在firebase中,顺序为imageListString,imageName,imageName1。但是在构造函数的模型中,您得到了String imageName,String imageName1,String imageListString。同时,我不确定在将列表发送到Firebase之前如何生成列表。
您可以尝试此方法