[英]How to convert base64 string to FormFile
Note: I am currently working on the api part of the app and I have no access to the frontend stuff.注意:我目前正在研究应用程序的 api 部分,我无法访问前端的内容。
So the frontend will send me a base64
string that I need to convert to a FormFile
because the method that would upload files in s3 will only accept IFormFileCollection
so I will need to convert the base64
string to a Formile
and also it's too complicated to just refactor the whole upload method now.所以前端会向我发送一个
base64
字符串,我需要将其转换为FormFile
因为在 s3 中上传文件的方法将只接受IFormFileCollection
所以我需要将base64
字符串转换为Formile
并且它太复杂而无法重构现在整个上传方法。
Is there a way to do this?有没有办法做到这一点?
Thanks!谢谢!
something like就像是
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.