[英]How to convert base64 string to FormFile
注意:我目前正在研究应用程序的 api 部分,我无法访问前端的内容。
所以前端会向我发送一个base64
字符串,我需要将其转换为FormFile
因为在 s3 中上传文件的方法将只接受IFormFileCollection
所以我需要将base64
字符串转换为Formile
并且它太复杂而无法重构现在整个上传方法。
有没有办法做到这一点?
谢谢!
就像是
File.WriteAllBytes(@"c:\yourfile", Convert.FromBase64String(yourBase64String));
using (var stream = File.OpenRead(@"c:\yourfile"))
{
var formFileName = new FormFile(stream, 0, stream.Length, null, Path.GetFileName(stream.Name))
{
Headers = new HeaderDictionary(),
ContentType = "YOUR CONTENT TYPE HERE"
};
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.