所以我有以下代码可以从Facebook获取照片,并且我想将照片上传到Firebase存储中:
photoUrl = user.getPhotoUrl().toString();
photoUrl = photoUrl + "?type=large";
Picasso.get().load(photoUrl).into(profileImageView);
imageUri = Uri.parse(photoUrl);
网址类似于:https://graph.facebook.com/“ NUMBER” /图片?type = large 我尝试使用此代码上传照片,但无法正常工作,我也不知道为什么。
final ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog.setTitle("Settings Account Information");
progressDialog.setMessage("Va rugam asteptati. ");
progressDialog.show();
if (imageUri != null) {
final StorageReference fileRef;
if (getType.equals("Agenti")) {
fileRef = storageProfilePicsRef.child("AgentiProfile")
.child(mAuth.getCurrentUser().getUid() + ".jpg");
} else {
fileRef = storageProfilePicsRef.child("ClientiProfile")
.child(mAuth.getCurrentUser().getUid() + ".jpg");
}
// I used a lot of Log.d and right here is stopping to show me something.
Something from here below is wrong..
uploadTask = fileRef.putFile(imageUri);
uploadTask.continueWithTask(new Continuation() {
@Override
public Object then(@NonNull Task task) throws Exception {
if (!task.isSuccessful()) {
throw task.getException();
}
return fileRef.getDownloadUrl();
}
}).addOnCompleteListener(new OnCompleteListener<Uri>() {
@Override
public void onComplete(@NonNull Task<Uri> task) {
if (task.isSuccessful()) {
Uri downloadUrl = task.getResult();
myUrl = downloadUrl.toString();
HashMap<String, Object> userMap = new HashMap<>();
userMap.put("uid", mAuth.getCurrentUser().getUid());
userMap.put("name", nameEditText.getText().toString());
userMap.put("phone", phoneEditText.getText().toString());
userMap.put("image", myUrl);
if (getType.equals("Agenti")) {
userMap.put("specializare", specializareEditText.getText().toString());
}
databaseReference.child(mAuth.getCurrentUser().getUid()).updateChildren(userMap);
progressDialog.dismiss();
}
}
});
}
有人可以帮我吗?
答案 0 :(得分:0)
我在这里发现了一个answear:https://stackoverflow.com/a/40345074/9027242 您可以只使用这样的链接:“为什么要上传,当您拥有由Facebook托管的链接时,您可以使用该链接”为什么我没有想到呢? :(