简体   繁体   中英

How to download a file to the default storage location using HTTP Response from a given URL

I am new to C# and reactjs and am stuck in this conundrum. I am using a function to download the images from url into my local file. Doing that I am specifying the file path.

The function is this:

[HttpPost]
        [Route("GetImages")]
        public IHttpActionResult GetImages()
        {
            Somewhere();
            using (WebClient webClient = new WebClient())
            {

                var url = "https://firebasestorage.googleapis.com/v0/b/tsl-coil-qlty- 
                           monitoring-dev.appspot.com/o/1a60ce3b-eddf-4e72-b2af-b6e99873e926? 
                           alt=media&token=61399a02-1009-4bb9-ad89-d1235df900e4";
                webClient.DownloadFile(url, @"D:\CQMS_Images_JPEG\image4.jpg");
            }
        
            return Ok();

        }

The problem is I am specifying a file path in the function. Can it be made so that I do not need to specify the file path and it will get downloaded to a default location.

Please help also please let me know if this can be done with HTTP Response?

The file path that I am giving here is "D:\CQMS_Images_JPEG\image4.jpg"

There are multiple ways to solve this issue -

  1. You can create an entry inside configuration section in web config that will have location information and use that value inside DownloadFile function instead of hard code path. 在此处输入图像描述

在此处输入图像描述

  1. You can create a folder inside your application and use the Server.MapPath to get that location. eg - You have folder name abc then you will get exact path by - 在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM