• asp.net 图片下载


             string fileName = "123.jpg";//图片名字
                        string filePath = Server.MapPath("../upload/123.jpg");//图片路径
           
                        //以字符流的形式下载文件
                        FileStream fs = new FileStream(filePath, FileMode.Open);
                        byte[] bytes = new byte[(int)fs.Length];
                        fs.Read(bytes, 0, bytes.Length);
                        fs.Close();
                        Response.ContentType = "application/octet-stream";
                        //通知浏览器下载文件而不是打开
                        Response.AddHeader("Content-Disposition", "attachment;  filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
                        Response.BinaryWrite(bytes);
                        Response.Flush();

    //此处可以加上下载量的计算

             Response.End();

  • 相关阅读:
    决定迁移过来,深耕于此。。。
    一篇搞定MongoDB
    一篇搞定vue请求和跨域
    自定义全局组件
    一篇搞定vue-router
    一篇搞定Vuex
    vue系列
    .Vue.js大全
    一篇搞定spring Jpa操作数据库
    自定义admin
  • 原文地址:https://www.cnblogs.com/dreamzcy/p/3184368.html
Copyright © 2020-2023  润新知