c# API接受圖片文件以Base64格式上傳圖片

/// 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(); }
相關文章
相關標籤/搜索