[英]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.