C# Base64上传文件

/// <summary>
/// 图片上传
/// </summary>
/// <param name="base64"></param>
/// <returns></returns>
public string UploadPic(string base64)
{
    var obj = new object { };
    string fileName = string.Empty;
    try
    {
        byte[] bytes = Convert.FromBase64String(base64.Split(',')[1]);
        MemoryStream ms = new MemoryStream(bytes);
        ms.Write(bytes, 0, bytes.Length);
        var img = Image.FromStream(ms, true);
        //图片绝对路径
        var path = System.AppDomain.CurrentDomain.BaseDirectory;
        var uploadurl = "UpFiles/autographImg/actualSales/";
        var imagesPath = System.IO.Path.Combine(path, uploadurl);
        //判断文件夹是否存在
        if (!System.IO.Directory.Exists(imagesPath))
        {
            System.IO.Directory.CreateDirectory(imagesPath);
        }
        //文件名
        fileName = DateTime.Now.ToString("yyyyMMddHHmmss_ffff", System.Globalization.DateTimeFormatInfo.InvariantInfo) + ".png";
        //保存图片
        img.Save(imagesPath + fileName);
        obj = new
        {
            errCode = 0,
            errMessage = "图片上传成功",
            imgurl = uploadurl + fileName
        };
    }
    catch (Exception ex)
    {
        obj = new { errCode = 4000, errMessage = ex.Message };
    }
    return JsonConvert.SerializeObject(obj);
}
后端开发

C# $的用法

2021-11-16 10:35:18

后端开发

C# DataTable转数组

2021-11-16 10:37:08

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索