【7.0】Base64转图片并上传
本帖最后由 x1061875478 于 2024-7-12 09:36 编辑看见论坛里有这个需求,做了个小demo大家一起参考
2021/10/29(链接更新)
补一个api文件:
https://www.aliyundrive.com/s/PpyzZ2AATkw
2024/07/12
此插件已经可以实现,大家就不用下这个工程了
豪~豪插件合集 - 葡萄城市场 (grapecity.com.cn)
这个结合AI能做出很多场景 :victory:
大佬,求指导啊! ngqj 发表于 2021-10-28 18:20
大佬,求指导啊!
应该挺清楚的吧,有哪里不懂吗 x1061875478 发表于 2021-10-28 18:27
应该挺清楚的吧,有哪里不懂吗
感觉漏了些东西,达不到结果,用demo测试了一下,而且附带的那个api文件下不了 api还有吗,大佬。现在打不开了
追风 发表于 2024-5-22 23:28
api还有吗,大佬。现在打不开了
这个比较老了清理了,可以使用这个插件功能来实现类似操作 追风 发表于 2024-5-22 23:28
api还有吗,大佬。现在打不开了
public async Task UpBase64Image()
{
IFormCollection postdata = await this.Context.Request.ReadFormAsync(new CancellationToken());
StringValues stringValues = postdata["base64Str"];
string base64Str = ((StringValues) ref stringValues);
base64Str = base64Str.Substring(base64Str.IndexOf(",") + 1);
stringValues = postdata["FileName"];
string FileName = ((StringValues) ref stringValues);
byte[] arr = Convert.FromBase64String(base64Str);
MyApi1.MyApi1.uploadResult result = new MyApi1.MyApi1.uploadResult();
string assemblyLocation = Assembly.GetExecutingAssembly().Location;
if (AppDomain.CurrentDomain.ShadowCopyFiles)
{
Uri uri = new Uri(Assembly.GetExecutingAssembly().CodeBase);
assemblyLocation = uri.LocalPath;
uri = (Uri) null;
}
string dir = Path.GetDirectoryName(assemblyLocation);
DirectoryInfo theFolder = new DirectoryInfo(dir);
DirectoryInfo path = theFolder.Parent;
string saveFilePath = path?.ToString() + "\\GeneratedResources\\Upload";
if (!Directory.Exists(saveFilePath))
Directory.CreateDirectory(saveFilePath);
string upFileName = FileName;
char[] a = new char{ '\\' };
string file_name = DateTime.Now.ToFileTime().ToString() + "_" + upFileName + ".jpg";
if (file_name == "")
{
saveFilePath = "";
result.code = -1;
result.msg = "客户端文件不存在!";
postdata = (IFormCollection) null;
base64Str = (string) null;
FileName = (string) null;
arr = (byte[]) null;
result = (MyApi1.MyApi1.uploadResult) null;
assemblyLocation = (string) null;
dir = (string) null;
theFolder = (DirectoryInfo) null;
path = (DirectoryInfo) null;
saveFilePath = (string) null;
upFileName = (string) null;
a = (char[]) null;
file_name = (string) null;
}
else
{
saveFilePath = Path.Combine(saveFilePath, file_name);
using (MemoryStream ms = new MemoryStream(arr))
{
Bitmap bmp2 = new Bitmap((Stream) ms);
bmp2.Save(saveFilePath, ImageFormat.Jpeg);
bmp2.Dispose();
bmp2 = (Bitmap) null;
}
result.code = 0;
result.msg = "上传成功!";
result.src = saveFilePath;
Dictionary<string, object> values = new Dictionary<string, object>();
string src = "/GeneratedResources/UpLoad/" + file_name;
values.Add("图片", (object) src);
this.DataAccess.AddTableData("表2", values);
values = (Dictionary<string, object>) null;
src = (string) null;
postdata = (IFormCollection) null;
base64Str = (string) null;
FileName = (string) null;
arr = (byte[]) null;
result = (MyApi1.MyApi1.uploadResult) null;
assemblyLocation = (string) null;
dir = (string) null;
theFolder = (DirectoryInfo) null;
path = (DirectoryInfo) null;
saveFilePath = (string) null;
upFileName = (string) null;
a = (char[]) null;
file_name = (string) null;
}
}
public class uploadResult
{
public int code { get; set; }
public string msg { get; set; }
public string src { get; set; }
}这是工程里反编译出来的,跟原来的应该不一样,大致逻辑可以参考的 x1061875478 发表于 2024-5-23 10:54
这是工程里反编译出来的,跟原来的应该不一样,大致逻辑可以参考的
好的,我去试试。感谢
页:
[1]
2