我能够将图像插入到firebase.storage中,但是我获得的下载链接与上载图像时所附加的下载链接不同。
public void UploadImage()
{
if (filePath != null)
progressBar.Visibility = ViewStates.Visible;
var images = storageRef.Child("profilePicture");
images.PutFile(filePath);
}
void IOnSuccessListener.OnSuccess(Java.Lang.Object result)
{
var snapShot = (UploadTask.TaskSnapshot)result;
var downloadURL = snapShot.DownloadUrl.Scheme
+ ":" + snapShot.DownloadUrl.SchemeSpecificPart;
}
UserData newUser = new UserData();
newUser.UserId = UserId;
newUser.Email = UserEmail;
newUser.FirstName = first.Text;
newUser.LastName = last.Text;
newUser.MobileNumber = phone.Text;
newUser.Userprofile = storageRef.DownloadUrl;
答案 0 :(得分:1)
我可以共享Android和IOS本机代码,以从Firebase上传的图像/文件获取URL,也许您可以从Xamarin那里获得一些帮助。
Android:
Task<Uri> urlTask = 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();
}
// Continue with the task to get the download URL
return fileRef.getDownloadUrl();
}
}).addOnCompleteListener(new OnCompleteListener<Uri>() {
@Override
public void onComplete(@NonNull Task<Uri> task) {
if (task.isSuccessful()) {
Uri downloadUri = task.getResult();
String stringUrl = downloadUri.toString(); // Image url
} else {
// Handle failures
Log.e("oops","problem occurred");
}
}
});
IOS:
fileRef.downloadURL { (url, error) in
guard let downloadURL = url else {
// Uh-oh, an error occurred!
print("Uh-oh, an error occurred! in url downloading")
return
}
print("downloadurl: \(downloadURL.absoluteString)");
}