JeffreySu / WeiXinMPSDK

微信全平台 .NET SDK, Senparc.Weixin for C#,支持 .NET Framework 及 .NET Core、.NET 8.0。已支持微信公众号、小程序、小游戏、微信支付、企业微信/企业号、开放平台、JSSDK、微信周边等全平台。 WeChat SDK for C#.
https://weixin.senparc.com
Apache License 2.0
8.4k stars 4.35k forks source link

CO2NET.HttpUtility.Get.Download(url, filePath) 无法保存自定义的文件名字 #1576

Closed i-shanghai closed 5 years ago

i-shanghai commented 5 years ago
问题描述

CO2NET.HttpUtility.Get.Download(url, filePath) 无法保存filePath中自定义的文件名字 CO2NET 依旧保存的是随机字符串

问题重现

Sample(.NET45)项目中,加入以下方法,传递文件名字参数 最终保存到了dir路径 下面,但是没有保存文件名字:DownloadImage_TEST.jpg 而是保存了:SenparcWechatCourse\Images\20190112-164423fcac24

public ActionResult GetImage(string url = "http://sdk.weixin.senparc.com/images/book-cover-front-small-3d-transparent.png") { var filePath = Server.MapPath("~/Images/") + "DownloadImage_{0}.jpg".FormatWith("TEST");

        var downloadResult = CO2NET.HttpUtility.Get.Download(url, filePath);

        return Content("图片下载成功:" + downloadResult);
    }
发现问题的模块
模块对应的 .net 版本
开发环境
i-shanghai commented 5 years ago

已经看到SDK下载的文件,只指定保存到 某个路径+随机文件名 自定义文件名需要,再对已经保存的文件重命名:

///

/// Get.Download方法下载URL图片 /// /// /// public ActionResult GetImage(string url = "http://sdk.weixin.senparc.com/images/book-cover-front-small-3d-transparent.png") { //保存后,SDK会随机分配文件名,不带后缀 var filePath = Server.MapPath("~/Images/"); var fileSaved = Senparc.CO2NET.HttpUtility.Get.Download(url, filePath);

        //文件重命名
        var newFileName = fileSaved + ".png";
        System.IO.File.Move(fileSaved, newFileName);

        return Content("图片下载成功:" + newFileName);
    }
JeffreySu commented 5 years ago

对的,目前是这样的,因为下载的某些文件名可能会包含非法的字符串。