c# API接受图片文件以文件格式上传图片
程序员文章站
2022-04-04 10:19:30
/// 文件图片上传 /// /// 成功上传返回上传后的文件名 [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(); }
上一篇: 全球真第一折叠手机 三星Galaxy Fold发布已量产
下一篇: 4G手机相关功能介绍