'Call to post method is not passing array of strings

I am calling API post method using axios in my React application, the post method has two parameters, 1 parameter as just a string and 2nd parameter is array of strings, the first parameter from left that is just string is being passed to the API correctly but the array of strings is not being passed. What's wrong with it?

    handleDownload = (e) => {
    e.preventDefault();

    var formData = new FormData();
    formData.append('communityname', this.state.selectedCommunity);
    formData.append('files', this.state.files);

    axios({
        method: 'post',
        url: clientConfiguration['filesApi.local'],
        data: formData
    });
}

And my API method is as below:

        [HttpPost]
    public FileContentResult Post([FromForm] string communityName, [FromForm] string[] files) 
    {           
        string rootPath = Configuration.GetValue<string>("ROOT_PATH");
        string communityPath = rootPath + "\\" + communityName;

        byte[] theZipFile = null;

        using (MemoryStream zipStream = new MemoryStream())
        {
            using (ZipArchive zip = new ZipArchive(zipStream, ZipArchiveMode.Create, true))
            {
                foreach (string attachment in files)
                {
                    var zipEntry = zip.CreateEntry(attachment);

                    using (FileStream fileStream = new FileStream(communityPath + "\\" + attachment, FileMode.Open))
                    using (Stream entryStream = zipEntry.Open())
                    {
                        fileStream.CopyTo(entryStream);
                    }
                }
            }
            theZipFile = zipStream.ToArray();
        }

        return File(theZipFile, "application/zip", communityName + ".zip");
    }

And I am getting the files parameter value as below, the client script is posting the files as one string as "[object Object],[object Object],[object Object],[object Object]" instead of separate string of arrays.



Solution 1:[1]

Maybe this could work better

let url = clientConfiguration['filesApi.local'];
let data = formData
axios.post(url, {data});

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dharman