我想保存上传的文件路径到数据库。为此,Firebase为我提供上传文件的URI:taskSnapshot.getDownLoadUrl()
。现在,我需要将它保存到数据库中,以便以后使用。怎样才能把它保存为:
taskSnapshot.getDownLoadUrl().toString
或taskSnapshot.getDownLoadUrl().getPath()
为了进行测试,我尝试将上传的图像文件加载到图像视图中,使用上面的字符串作为load()方法参数。toString工作,但getPath不工作。
发布于 2016-11-03 12:14:28
当您获得taskSnapshot的taskSnapshot时,它将返回一个uri,如果然后使用toString(),则会得到一个包含图像下载url的字符串,但是如果您请求路径,它将不会返回任何内容,因为taskSnapShot.getDownloadUrl()返回的uri并不是分层的。如果希望防火墙存储上的文件路径通过存储引用(而不是URL )访问它,则可以使用taskSnapshot.getStorage()。
发布于 2016-11-03 12:04:51
来自Firebase文档:
getDownloadUrl
String
A URL that can be used to download the object.
This is a public unguessable URL that can be shared with other clients.
This value is populated once an upload is complete.
您应该使用getDownloadUrl并将其保存到Uri中,然后可以将Uri.tostring与幻灯片一起使用。
Uri downloadUrl = taskSnapshot.getDownloadUrl();
另一个选项是使用FirebaseUI存储,您应该保存storageReference,然后可以使用它
Glide.with(this /* context */)
.using(new FirebaseImageLoader())
.load(storageReference)
.into(imageView);
https://stackoverflow.com/questions/40400102
复制相似问题