当前位置: 首页 > 知识库问答 >
问题:

我想获得图像url,但getDownloadUrl()不工作?[副本]

姚臻
2023-03-14
private void upload_product() {
 if(mImageUri != null){
  final StorageReference fileReference = 
    mStorageRef.child(System.currentTimeMillis()
        +"."+getFileExtension(mImageUri));

        uploadProgressBar.setVisibility(View.VISIBLE);
        uploadProgressBar.setIndeterminate(true);

        mUploadTask = fileReference.putFile(mImageUri)
         .addOnSuccessListener(new 
           OnSuccessListener<UploadTask.TaskSnapshot>() {
            @Override
             public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
              Handler handler = new Handler();
              handler.postDelayed(new Runnable() {
              @Override
              public void run() {
               uploadProgressBar.setVisibility(View.VISIBLE);
               uploadProgressBar.setIndeterminate(false);
               uploadProgressBar.setProgress(0);
              }
            },500);
        Toast.makeText(Add_Item.this, "Product Upload Successful", 
         Toast.LENGTH_SHORT).show();
        StorageSchema upload = new StorageSchema(
               productname.getText().toString().trim(),
               productdescription.getText().toString(),

              //the problem is here in getDownloadUrl() method 

               taskSnapshot.getDownloadUrl().toString());
               String uploadId = mDatabaseRef.push().getKey();
               mDatabaseRef.child(uploadId).setValue(upload);
               uploadProgressBar.setVisibility(View.INVISIBLE);
              }
         });
    }
}


//starting the StorageSchema class having the schema
public class StorageSchema {

private String productname;
private String productdescription;
private String imageUrl;
private int rate;
private String unit;
private int position;
private String key;


public StorageSchema(){
    //empty constructor needed
}

public StorageSchema(int position){
    this.position=position;
}

public StorageSchema(String productname, String productdescription, String 
imageUrl, int rate, String unit){
if(productname.trim().equals("")){
    productname = "No Name";
}
this.productname = productname;
this.productdescription = productdescription;
this.imageUrl = imageUrl;
this.rate = rate;
this.unit = unit;
}

我想使用getDownloadUrl(),如果现在由于最新版本而不支持,那么我如何获得图像URL。

共有1个答案

魏鸿禧
2023-03-14
Task<Uri> urlTask = mUploadTask.continueWithTask(task -> {
                if (!task.isSuccessful()) {
                    throw task.getException();
                }

                // Continue with the task to get the download URL
                return fileReference.getDownloadUrl();
            }).addOnCompleteListener(task -> {
                if (task.isSuccessful()) {
                    Uri downloadUri = task.getResult();
                    if (downloadUri != null) {
                        // HERE IS YOUR DL LINK
                        String dl =  downloadUri.toString();
                    }

                } else {
                       // SOMETHING WENT WRONG 
                }
            });
 类似资料:
  • 我用了docker,想删除所有东西 所以我试着移除它,但它并没有消失

  • 比如去http://en.wikipedia.org/w/api.php?action=query 但有些图像不返回url,例如Image:Wodan_Heilt_Balders_Pferd_by_eml_Doepler.jpg。所以如果我去http://en.wikipedia.org/w/api.php?action=query 除了imageinfo不存在之外,我注意到的一点是,似乎确实返回

  • 我试过不同的浏览器,有没有使用%20,但我知道使用%20才是正确的方法。(实际上,这两种浏览器都可以使用) 我知道图像只会在托管它的机器上可见,这不是问题。

  • 出于某种原因,我的图像图标正在出现错误,尽管我试图修复它... 我读过这个问题,答案建议在mitmap文件夹中创建图像图标。因此,我将代码行从更改为 您可以看到图像上有一个错误。为什么会这样? 我曾试图: 清洁项目 重建项目 确保@mitmap/ic_启动器确实存在: 即使在我所有的尝试之后,错误仍然存在。我已经被困在这个问题上好几个小时了,我的脑袋都转不过来了。这是我的代码还是android s

  • 问题内容: 我正在尝试获取Firebase存储桶中文件的“长期持久下载链接”。我已将其权限更改为 我的javacode看起来像这样: 当我运行它时,我得到的uri链接看起来像 com.google.android.gms.tasks.zzh@xxx 问题1.我是否可以从中获得类似于以下内容的下载链接:https : //firebasestorage.googleapis.com/v0/b/pro

  • 我用textview来显示温度,应该是这样的 当我更改textSize时,它显示如下所示 我只是想改变textview的大小,但我不想它变得更厚,我该如何处理这个问题呢?