【发布时间】:2017-03-29 15:13:08
【问题描述】:
我正在制作一个应用程序,用户可以在其中拍摄和上传照片,而另一个用户可以在ImageView 中下载和查看它。为了防止我占用应用程序的所有内存,我将整个图片存储在存储空间中。
它已与此处的标准公式一起使用; https://firebase.google.com/docs/storage/android/download-files
问题是,我不知道如何获取图像下载到的路径。我在 AVD 监视器中找不到它,我需要每个下载图片的 URL,因为它将是自定义的。我尝试使用这样的东西,它会创建一个新目录并将其放在那里,但它不起作用,我也找不到路径。
public void getImageFromPath() throws IOException {
StorageReference islandRef = storageRef.child("userimages/test@test.dk/test@test.dk");
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File directory = new File(Environment.getDataDirectory()
+ "/Test/");
if (!directory.exists()) {
directory.mkdir();
}
final File localFile = File.createTempFile(imageFileName, ".jpg", directory);
try {
islandRef.getFile(localFile).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
@Override
public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
Toast.makeText(getApplicationContext(), "Downloaded", Toast.LENGTH_SHORT).show();
Log.d(TAG, "Downloaded til path");
String mCurrentPhotoPath = "file:" + localFile.getAbsolutePath();
System.out.println(mCurrentPhotoPath);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
Log.d(TAG, "Downloaded IKKE til path");
}
});
throw new IOException("Works not");
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
}
【问题讨论】:
标签: android firebase firebase-storage