c# API接受图片文件以文件格式上传图片

匿名 (未验证) 提交于 2019-12-02 22:06:11
   /// 文件图片上传          /// </summary>          /// <returns>成功上传返回上传后的文件名</returns>         [HttpPost]         public async Task<IHttpActionResult> UpLoadImageFiles()         {              var files = HttpContext.Current.Request.Files;             if (files.AllKeys.Any())             {                 using (HttpClient client = new HttpClient())                 {                     HttpContextBase HttpContext = (HttpContextBase)Request.Properties["MS_HttpContext"];                     var request = new HttpRequestMessage(HttpMethod.Post, ConfigurationManager.AppSettings["SaveToImgaes"].ToString() + "/Upload/");                     var content = new MultipartFormDataContent();                     content.Add(new StreamContent(HttpContext.Request.Files[0].InputStream), "file", "file.jpg");                     request.Content = content;                     var response = await client.SendAsync(request);                     response.EnsureSuccessStatusCode();                     var filenamestr = await response.Content.ReadAsStringAsync();//结果                 }             }             return Ok();         }

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!