I’ve tried to send all datatable with file (serialize the table) and send all to backed using golang.
I will have to move files to some directory but dont know how to send all array of Files at once from webix.
For single file I’m using fiber - c.FormFile("uploader")
but now since it’s in array I will have to use c.MultipartForm()
adding this
onBeforeAjax: function (mode, url, data, request, headers, files) {
headers["Content-Type"] = "multipart/form-data";
}
but still not working. Do you have any sample of this?
my final goal is to move files to specific directory - rename - return new name to the record - add the data to database (I can do it one by one from c.FromFile by upload to temporary folder first but this is not what it supposed to.
or Can we upload using datatable instead?
webix.ajax().headers({ 'Content-Type': 'multipart/form-data' }).post(api, table_row_record, function (text) {
console.log(text);
});
Im getting this message from go error;
Error: request has no multipart/form-data Content-Type
You can modify your last example a little bit. Use a cycle for
:
const files = $$("upload_table").serialize();
const formData = new FormData();
for (let i = 0; i < files.length; i++)
formData.append(files[i].name, files[i].file)
and upload data by ajax
:
webix.ajax()
.headers({ 'Content-Type': 'multipart/form-data' })
.post("//docs.webix.com/samples/server/films", formData);
Please, check out the snippet: Code Snippet