Download file from webservice - in ASP.NET site

后端 未结 4 2401
没有蜡笔的小新
没有蜡笔的小新 2021-02-20 14:00

I want to push a file to the browser from a website using a webservice. I\'m currently reading the file into a base64 byte array, and returning that from the webservice. This w

4条回答
  •  北恋
    北恋 (楼主)
    2021-02-20 14:12

    It's possible, you'll need to make sure you explicitly set the ContentType of the HttpResponse, for example:

    Response.ContentType = "image/jpeg";
    Response.OutputStream.Write(buffer, 0, buffer.Length);
    

    If you want to control the file name, you'll have to add a Content-Disposition header. Google can help you find the right way to sort that out.

提交回复
热议问题