簡體   English   中英

如何將base64字符串轉換為FormFile

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM