找回密码
 立即注册

QQ登录

只需一步,快速开始

x1061875478

金牌服务用户

80

主题

327

帖子

1087

积分

金牌服务用户

积分
1087
x1061875478
金牌服务用户   /  发表于:2021-9-14 11:14  /   查看:3372  /  回复:9
本帖最后由 x1061875478 于 2022-9-28 13:05 编辑

看见论坛里有这个需求,做了个小demo大家一起参考 base64demo.gif


Base64图片保存并上传.fgcc (89.19 KB, 下载次数: 114, 售价: 30 金币)

评分

参与人数 3金币 +732 满意度 +5 收起 理由
ngqj + 5
Chelsey.Wang + 666 赞一个!
David.Zhong + 66 很给力!

查看全部评分

9 个回复

正序浏览
追风
注册会员   /  发表于:前天 11:25
10#
x1061875478 发表于 2024-5-23 10:54
这是工程里反编译出来的,跟原来的应该不一样,大致逻辑可以参考的

好的,我去试试。感谢
回复 使用道具 举报
x1061875478
金牌服务用户   /  发表于:前天 10:54
9#
追风 发表于 2024-5-22 23:28
api还有吗,大佬。现在打不开了
  1.     [Post]
  2.     public async Task UpBase64Image()
  3.     {
  4.       IFormCollection postdata = await this.Context.Request.ReadFormAsync(new CancellationToken());
  5.       StringValues stringValues = postdata["base64Str"];
  6.       string base64Str = ((StringValues) ref stringValues)[0];
  7.       base64Str = base64Str.Substring(base64Str.IndexOf(",") + 1);
  8.       stringValues = postdata["FileName"];
  9.       string FileName = ((StringValues) ref stringValues)[0];
  10.       byte[] arr = Convert.FromBase64String(base64Str);
  11.       MyApi1.MyApi1.uploadResult result = new MyApi1.MyApi1.uploadResult();
  12.       string assemblyLocation = Assembly.GetExecutingAssembly().Location;
  13.       if (AppDomain.CurrentDomain.ShadowCopyFiles)
  14.       {
  15.         Uri uri = new Uri(Assembly.GetExecutingAssembly().CodeBase);
  16.         assemblyLocation = uri.LocalPath;
  17.         uri = (Uri) null;
  18.       }
  19.       string dir = Path.GetDirectoryName(assemblyLocation);
  20.       DirectoryInfo theFolder = new DirectoryInfo(dir);
  21.       DirectoryInfo path = theFolder.Parent;
  22.       string saveFilePath = path?.ToString() + "\\GeneratedResources\\Upload";
  23.       if (!Directory.Exists(saveFilePath))
  24.         Directory.CreateDirectory(saveFilePath);
  25.       string upFileName = FileName;
  26.       char[] a = new char[1]{ '\\' };
  27.       string file_name = DateTime.Now.ToFileTime().ToString() + "_" + upFileName + ".jpg";
  28.       if (file_name == "")
  29.       {
  30.         saveFilePath = "";
  31.         result.code = -1;
  32.         result.msg = "客户端文件不存在!";
  33.         postdata = (IFormCollection) null;
  34.         base64Str = (string) null;
  35.         FileName = (string) null;
  36.         arr = (byte[]) null;
  37.         result = (MyApi1.MyApi1.uploadResult) null;
  38.         assemblyLocation = (string) null;
  39.         dir = (string) null;
  40.         theFolder = (DirectoryInfo) null;
  41.         path = (DirectoryInfo) null;
  42.         saveFilePath = (string) null;
  43.         upFileName = (string) null;
  44.         a = (char[]) null;
  45.         file_name = (string) null;
  46.       }
  47.       else
  48.       {
  49.         saveFilePath = Path.Combine(saveFilePath, file_name);
  50.         using (MemoryStream ms = new MemoryStream(arr))
  51.         {
  52.           Bitmap bmp2 = new Bitmap((Stream) ms);
  53.           bmp2.Save(saveFilePath, ImageFormat.Jpeg);
  54.           bmp2.Dispose();
  55.           bmp2 = (Bitmap) null;
  56.         }
  57.         result.code = 0;
  58.         result.msg = "上传成功!";
  59.         result.src = saveFilePath;
  60.         Dictionary<string, object> values = new Dictionary<string, object>();
  61.         string src = "/GeneratedResources/UpLoad/" + file_name;
  62.         values.Add("图片", (object) src);
  63.         this.DataAccess.AddTableData("表2", values);
  64.         values = (Dictionary<string, object>) null;
  65.         src = (string) null;
  66.         postdata = (IFormCollection) null;
  67.         base64Str = (string) null;
  68.         FileName = (string) null;
  69.         arr = (byte[]) null;
  70.         result = (MyApi1.MyApi1.uploadResult) null;
  71.         assemblyLocation = (string) null;
  72.         dir = (string) null;
  73.         theFolder = (DirectoryInfo) null;
  74.         path = (DirectoryInfo) null;
  75.         saveFilePath = (string) null;
  76.         upFileName = (string) null;
  77.         a = (char[]) null;
  78.         file_name = (string) null;
  79.       }
  80.     }

  81.     public class uploadResult
  82.     {
  83.       public int code { get; set; }

  84.       public string msg { get; set; }

  85.       public string src { get; set; }
  86.     }
复制代码
这是工程里反编译出来的,跟原来的应该不一样,大致逻辑可以参考的

评分

参与人数 1满意度 +5 收起 理由
追风 + 5

查看全部评分

回复 使用道具 举报
x1061875478
金牌服务用户   /  发表于:前天 10:50
8#
追风 发表于 2024-5-22 23:28
api还有吗,大佬。现在打不开了

这个比较老了清理了, image.png294268492.png 可以使用这个插件功能来实现类似操作
回复 使用道具 举报
追风
注册会员   /  发表于:3 天前
7#
api还有吗,大佬。现在打不开了
回复 使用道具 举报
ngqj
银牌会员   /  发表于:2021-10-29 14:16:56
6#
x1061875478 发表于 2021-10-28 18:27
应该挺清楚的吧,有哪里不懂吗

感觉漏了些东西,达不到结果,用demo测试了一下,而且附带的那个api文件下不了
回复 使用道具 举报
x1061875478
金牌服务用户   /  发表于:2021-10-28 18:27:35
5#
ngqj 发表于 2021-10-28 18:20
大佬,求指导啊!

应该挺清楚的吧,有哪里不懂吗
回复 使用道具 举报
ngqj
银牌会员   /  发表于:2021-10-28 18:20:27
地板
大佬,求指导啊!
回复 使用道具 举报
xiaoyeniao
初级会员   /  发表于:2021-10-9 18:51:13
板凳

回复 使用道具 举报
vickdracula活字格认证
中级会员   /  发表于:2021-9-14 14:48:54
沙发
这个结合AI能做出很多场景
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部