我目前正在我的recyclerView onBindViewholder中执行这些代码,但是我发现了堆栈溢出。
final DatabaseReference ref = getRef(position);
//update the uploaded node
final HashMap<String, Object> fullUploadUpdate = new HashMap<>();
fullUploadUpdate.put("uploaded", true);
StorageTask<UploadTask.TaskSnapshot> t1 = thumbUploadRef.putBytes(ImageUtils.compressImage(FileUtils.getPath(getContext(), filePath), 20))
.addOnSuccessListener(getActivity(), new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
fullUploadUpdate.put("thumbnailUri", taskSnapshot.getDownloadUrl());
}
});
StorageTask<UploadTask.TaskSnapshot> t2 = fullUploadRef.putFile(filePath)
.addOnProgressListener(getActivity(), new OnProgressListener<UploadTask.TaskSnapshot>() {
@Override
public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
double progress = (100.0 * taskSnapshot.getBytesTransferred()) / taskSnapshot.getTotalByteCount();
Timber.d("Upload is " + progress + "% done");
mpOutHolder.setUploadProgress(progress);
}
}).addOnSuccessListener(getActivity(), new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
fullUploadUpdate.put("fullImageUri", taskSnapshot.getDownloadUrl());
fullUploadUpdate.put("size", taskSnapshot.getTotalByteCount());
}
});
Tasks.whenAll(t1, t2).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
ref.updateChildren(fullUploadUpdate);
}
});
答案 0 :(得分:0)
问题出在我需要调用的HasMap上
taskSnapshot.getDownloadUrl().toString()