Alternative Response.TransmitFile for transferring files over HTTP

I am working on an ASP.NET site that allows users to upload files.

Previously, the files were stored on the same server as the website, so that we can:

Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
Response.AddHeader("Content-Length", response.ContentLength.ToString());
Response.ContentType = "application/octet-stream";
Response.TransmitFile(path);
Response.End();

However, now some files are stored on a separate server. I can check if files exist using

WebRequest request = WebRequest.Create(absolute-url);
WebResponse response = request.GetResponse();

But how can I facilitate the transfer, since TransmitFile requires a virtual path, not a URL?

I need so that users can choose where to save the file, as with a normal download on the Internet

What is the best way to do this?

+3
source share
4 answers

-, :

while ((read = stream.Read(buffer, offset, chunkSize)) > 0)    
{

    Response.OutputStream.Write(buffer, 0, read);
    Response.Flush();
}
+5

TransferFile . WriteFile .

+2
  • URL- ?
  • . "GetResponse", Response.
+1

, TransmitFile. , WebDAV , TransmitFile.

0

Source: https://habr.com/ru/post/1713083/


All Articles