/// base64上傳圖片 /// /// 成功上傳返回上傳後的文件名 [HttpPost] public async Task UpLoadImageBase64() { HttpContextBase context = (HttpContextBase)Request.Prope... ...
/// base64上傳圖片 /// </summary> /// <returns>成功上傳返回上傳後的文件名</returns> [HttpPost] public async Task<IHttpActionResult> UpLoadImageBase64() { HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"]; string text = context.Request.Form["file"]; Stream stream = new MemoryStream(Convert.FromBase64String(text.Split(',')[1])); using (HttpClient client = new HttpClient()) { var request = new HttpRequestMessage(HttpMethod.Post, ConfigurationManager.AppSettings["Imgaes"].ToString() + "/Upload"); var content = new MultipartFormDataContent(); //client.DefaultRequestHeaders.Add("fileext", HttpContext.Request.Headers["fileext"]); content.Add(new StreamContent(stream), "file", "file.jpg"); request.Content = content; var response = await client.SendAsync(request); response.EnsureSuccessStatusCode(); var filenamestr = await response.Content.ReadAsStringAsync();//返回結果 } return Ok(); }