/// 文件圖片上傳 /// /// 成功上傳返回上傳後的文件名 [HttpPost] public async Task UpLoadImageFiles() { var files = HttpContext.Current.Request.Files; ... ...
/// 文件圖片上傳 /// </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(); }