.net core picture processing related operations on

Typically, the front needs to have several ways to download images Photo Gallery or when, or generally direct return File returned byte array and then turn base64

You need a picture access interface, the interface returns to the format byte []

code show as below

Back-end code:

[HttpGet("GetAccessory")]
        public async Task<IActionResult> GetAccessory(string token,string ftpKey, string fn)
        {
            byte[] buffer = null;
            using (var httpClient = new HttpClient())
            {
                //url编码
                string fileName = System.Web.HttpUtility.UrlEncode(fn);
          //图片访问地址
                var requestUri = $"http://10.22.153.39:5000/api/resource/test/{ftpKey}/{fileName}";
                var httpResult = await httpClient.GetAsync(requestUri);
                buffer = await httpResult.Content.ReadAsByteArrayAsync();
            }
            var file = File(buffer , "image/jpeg");
            return file;
        }

About Http context - type table

Can be found here: https://www.runoob.com/http/http-content-type.html

Common media format types are as follows:

  • text / html: HTML format
  • text / plain: plain text
  • text / xml: XML format
  • image / gif: gif image formats
  • image / jpeg: jpg image format
  • image / png: png image format

Front-end code:

Download Link way:

< A the href = 'Address API' > image Download </ A >

image display:

<img src="http://localhost:5105/api" width="500" height="300">

 

Guess you like

Origin www.cnblogs.com/haixiaocan/p/11906192.html