Reputation: 439
Note: I am currently working on the api part of the app and I have no access to the frontend stuff.
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.
Is there a way to do this?
Thanks!
Upvotes: 3
Views: 5571
Reputation: 1606
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"
};
}
Upvotes: 2