.net core 3.1 webapi后端接收钉钉小程序post的文件/图片
1.netcore3.0 webapi集成Swagger 5.02.DingTalk钉钉消息推送(.net core 3 WebApi尝鲜记)
3..net core 3.1 webapi后端接收钉钉小程序post的文件/图片
4.asp.net core 3.1 webapi FileContentResult 5.一次asp.net core3.1打造webapi开发框架的实践6..net core3.1项目在centos7.6上部署经验7.ZR.Admin小改和VUE3版本体验8.我的微服务之路,看我搭建dapr趟过的坑9.42岁大龄程序员的迷茫,看我最新尝鲜.net 5+Dapper搭建的WebAPI框架10.Kestrel服务器ASP.NetCore 3.1程序启用SSL11.Asp.Net Core 下 Newtonsoft.Json 转换字符串 null 替换成string.Empty(转)12.ApiResult-WebAPI开发统一返回值对象的演化(.net core版) 13.体验.net core 3.1 socket世上本没路;走的人多了,便成了路。
dd.uploadFile({ url: '请使用自己服务器地址', fileType: 'image', fileName: 'file', filePath: '...', success: (res) => { dd.alert({ content: '上传成功' }); }, });
这就是官网上的例子,没有后端的。但是我猜这是用"Form"进行post提交的,那脑补后端可以在post请求的boby里获取这个文件。以下是成功的后端代码:
/// <summary> /// 用户上传头像 /// </summary> /// <param name="formCollection">Boby</param> /// <param name="userid">userid</param> /// <returns></returns> [HttpPost, Route("postPhotoImage")] public StatusCodeResult UserPostPhotoImage([FromForm] IFormCollection formCollection, string userid) { if (formCollection.Files.Count > 0) { var emp = JsonConvert.DeserializeObject<EmployeeDTO>(GetEmployeeInfo(userid)); string photo_path = @"C:\apache-tomcat-7.0.90\webapps\default\employeesProfilePicture\"; string photo_file = photo_path + emp.jobnumber + ".jpg"; if (System.IO.File.Exists(photo_file)) System.IO.File.Delete(photo_file); try { #region 存储文件 using (FileStream fs = System.IO.File.Create(photo_file)) { var file = formCollection.Files[0]; file.CopyTo(fs); int photo_width = 125; int photo_height = 184; Image img = ZoomImage(Image.FromStream(fs), photo_height, photo_width); using (MemoryStream msResult = new MemoryStream()) { Image resultImgage = new Bitmap(photo_width, photo_height); Graphics g = Graphics.FromImage(resultImgage); g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.Clear(Color.White); g.DrawImage(img, new RectangleF(0, 0, photo_width, photo_height)); resultImgage.Save(msResult, ImageFormat.Png); byte[] buffer = new byte[msResult.Length]; msResult.Seek(0, SeekOrigin.Begin); msResult.Read(buffer, 0, buffer.Length); msResult.Close(); fs.Write(buffer, 0, buffer.Length); } fs.Flush(); Console.WriteLine(Environment.NewLine + "=========================*==========================="); Console.WriteLine(DateTime.Now + "->:Upload Photo,FileName:" + fs.Name); Console.WriteLine("=========================*===========================" + Environment.NewLine); } #endregion return Ok(); } catch (Exception) { return BadRequest(); } } else return BadRequest(); }
大伙需要注意[FromForm]标记,[FromBoby]是获取不到的!
let debug_domain='http://cquni.vaiwan.com:8771/api/ECard'; let domain ="http://218.?.?.?:8771/api/ECard"; let post_url=domain+'/postPhotoImage'; let photo_path=''; let current_user=''; Page({ data: { src: '' }, onLoad(query) { current_user=query.userid; }, photoselect(event){ let that = this; dd.chooseImage({ count: 1, success: (res) => { photo_path=res.filePaths[0]; that.setData({ src:res.filePaths[0] }); }, }); }, postimage(event){ const file_url = post_url+'?userid='+current_user; if (photo_path==''){ dd.alert({ title:'出错啦!', content: '请先选取或拍摄照片!预览满意后再提交上传。', buttonText:'我晓得了' }); return; } //dd.alert({content:file_url}); dd.uploadFile({ url: file_url, fileType: 'image', fileName: 'employee_photo', filePath: photo_path, success: (res) => { dd.alert({ title:'恭喜', content: '操作成功,头像已上传!', buttonText:'我晓得了' }); }, }); } });
作者:数据酷软件
出处:https://www.cnblogs.com/datacool/p/12365105.html
关于作者:20年编程从业经验,持续关注MES/ERP/POS/WMS/工业自动化
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明。
联系方式: qq:71008973;wx:6857740733
基于人脸识别的考勤系统 地址: https://gitee.com/afeng124/viewface_attendance_ext
自己开发安卓应用框架 地址: https://gitee.com/afeng124/android-app-frame
WPOS(warehouse+pos) 后台演示地址: http://47.239.106.75:8080/
合集:
.net core随笔
分类:
程序设计
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探