About Web download files, using data flow mode to download

Source: Internet
Author: User

About file download, many are used href= ' file address ', this is very insecure, so need to use to file stream, the following code is used to download a picture.

Response.bufferoutput =false;        Response.Clear (); Response.ContentType="Application/x-msdownload"; Response.appendheader ("content-disposition","attachment; Filename="+"Coupon . jpg"); Response.ContentType="Application/octstream"; Response.CacheControl="Private"; System.IO.Stream STM=NewSystem.IO.FileStream (Server.MapPath ("~/uploadfiles/youhui/"+path), System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read); Response.appendheader ("Content-length", STM.        Length.tostring ()); System.IO.BinaryReader BR=NewSystem.IO.BinaryReader (STM); byte[] bytes;  for(Int64 x =0; x < (Br. Basestream.length/4096+1); X + +) {bytes= Br. Readbytes (4096);            Response.BinaryWrite (bytes); System.Threading.Thread.Sleep (5); }

About Web download files, using data flow mode to download

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.