Home > Net >  How to add multiple .AddFile in FLurl?
How to add multiple .AddFile in FLurl?

Time:06-01

I have this code will implement Flurl to call web api. But it only works for one file as I have fixed to the first element of SupportingDocs list object.

var response = await url.SetQueryParams(new { id, code })                     
        .PostMultipartAsync(mp => mp
        .AddFile("SupportingDocs", postData.SupportingDocs[0].FileContent, 
            postData.SupportingDocs[0].FileName)
        );   

How do I add a foreach inside so that it can support multiple element for SupportingDocs which is a list object.

CodePudding user response:

You can rewrite the action delegate like this:

var response = await url.SetQueryParams(new { id, code })                     
    .PostMultipartAsync(mp => 
    {
        foreach (var doc in postData.SupportingDocs)
        {
            mp = mp.AddFile("SupportingDocs", doc.FileContent, doc.FileName);
        }
    });
  • Related