年少的隔壁老王 2018-05-02 08:04 采纳率: 60%
浏览 2501
已结题

ftp得到的流转base64图片

FtpWebRequest reqFTP;
        string ftpUrl = "ftp://a.png";
        reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpUrl));
        reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
        reqFTP.UseBinary = true;
        reqFTP.Credentials = new NetworkCredential("123", "123456");
        reqFTP.UsePassive = false; 
        reqFTP.KeepAlive = false;
        FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
        Stream ftpStream = response.GetResponseStream();

        MemoryStream mStream = new MemoryStream();
        ftpStream.CopyTo(mStream);
        byte[] arr = new byte[mStream.Length];
        mStream.Position = 0;
        mStream.Read(arr, 0, (int)mStream.Length);

        byte[] bytes = mStream.GetBuffer();
        string base64 = Convert.ToBase64String(bytes);
        mStream.Close();
        return base64; 

                    得到的base64图片,在前端显示不出来
  • 写回答

2条回答 默认 最新

  • fu_chenchen6473 2018-05-02 08:04
    关注

    Java将二进制流转Base64字符串并在页面显示(附Base64转二进制流)

    java代码如下:

    /**

     * 二进制流转Base64字符串
     *
     * @param data 二进制流
     * @return data
     * @throws IOException 异常
     */
    public static String getImageString(byte[] data) throws IOException {
        BASE64Encoder encoder = new BASE64Encoder();
        return data != null ? encoder.encode(data) : "";
    }
    
    
    /**
     * Base64字符串转 二进制流
     *
     * @param base64String Base64
     * @return base64String
     * @throws IOException 异常
     */
    public static byte[] getStringImage(String base64String) throws IOException {
        BASE64Decoder decoder = new sun.misc.BASE64Decoder();
        return base64String != null ? decoder.decodeBuffer(base64String) : null;
    }
    

    前台页面代码如下:

    前台用的是freemarker模板引擎


    <#if (picList??) >


      <#list picList as pl>

    • style='border:none; padding-right:5px;'/>

    • </#list>


    </#if>

    效果如图:

    评论

报告相同问题?

悬赏问题

  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的