Parsing form data - kotC9/VueNancy GitHub Wiki

Let's say we need to send some photos for storage to the server, save your photos in variable dropFiles any way.

Next, fill the formData with ours files, where 'files[' + i + ']' is unique key:

let formData = new FormData();
for (var i = 0; i < this.dropFiles.length; i++) {
    let file = this.dropFiles[i];
    formData.append('files[' + i + ']', file);
}

And send it with axios:

axios
     .post('localhost:8081/api/send-images',
         formData, {
             headers: {
                 'Content-Type': 'multipart/form-data'
             }
         }
     )
     .then(() => {
         //alert("ok");
     }, (error) => {
         alert(error);
     });

Now we just have to get this data on server. Fortunately, the nancyfx will do everything for us:

Post("/send-images", args =>
{
    //get files from request (Request.Files returns Ienumerable<HttpFile>)
    var files = Request.Files.ToArray();
    foreach(var file in files)
    {
        // DoSomething();
    }
}
⚠️ **GitHub.com Fallback** ⚠️