I have this form that has a drag and drop. Using this plugin.
The code creates a drag and drop that auto triggers an upload.
<div class="form-group g-mb-30">
<label class="g-mb-10" for="inputGroup-3_1">Image *</label>
<div class="g-pos-rel">
<span class="g-pos-abs g-top-0 g-right-0 d-block g-width-40 h-100 opacity-0 g-opacity-1--success">
<i class="hs-admin-check g-absolute-centered g-font-size-default g-color-lightblue-v3"></i>
</span>
<input class="js-file-attachment" name="fileAttachment2[]" type="file" id="ka-file">
</div>
</div>
Now in this object I set a couple options to process my form.
uploadFile: {
url: '/FileUpload/Upload',
data: document.getElementById('ka-file').files[0],
type: 'POST',
enctype: 'multipart/form-data',
beforeSend: function() {
formData = document.getElementById('ka-file').files[0];
console.log(formData);
},
}
I'm getting the element by Id and sending that data. I know I'm sending the data because on my console log in the function beforeSend I get output.
In my controller I'm receiving the data like this.
[HttpPost]
public async Task<IActionResult> Upload(IFormFile file)
{
if(file == null)
{
return Ok(200);
}
}
But my file is always null. I'm not sure what I'm missing.
