简体   繁体   English

从 xamarin forms 中的 base64 下载文件

[英]Download file from base64 in xamarin forms

I'm trying to download a file (that can be either image or PDF) that I've saved in my DB.我正在尝试下载已保存在数据库中的文件(可以是图像或 PDF)。 I get the file in a string format, so I want to download this file.我得到一个字符串格式的文件,所以我想下载这个文件。 The problem is, I don't get any error, it just doesn't show the downloaded file on its folder.问题是,我没有收到任何错误,只是没有在其文件夹中显示下载的文件。 Here is what I have so far.这是我到目前为止所拥有的。

                string caminho = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                string caminho_arquivo = Path.Combine(caminho, nome_arquivo);
                var decoded = Encoding.UTF8.GetString(Convert.FromBase64String(arquivo.arquivo));
                File.WriteAllText(caminho_arquivo, decoded);

The code below:下面的代码:

  string caminho = Environment.GetFolderPath(Environment.SpecialFolder.Personal);

would show the path like:将显示如下路径:

"/data/user/0/packagename/files/filename"

In Internal Storage, you couldn't see the files without root permission.在内部存储中,没有 root 权限是看不到文件的。

But you could use the code to check the file exist or not in the internal storage.但是您可以使用代码来检查文件是否存在于内部存储中。

  if (File.Exists(caminho_arquivo))
        {

        }

If you want to view it, you could use adb tool.如果你想查看它,你可以使用adb工具。 Please refer to the way in the link about the adb tool.关于adb工具请参考链接中的方式。 How to write the username in a local txt file when login success and check on file for next login? 登录成功时如何将用户名写入本地txt文件并检查文件以进行下次登录?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM