参考信息 {#menu_index_1}
示例代码 {#menu_index_2}
let fileItem = new File([blob], "example.txt", {
type: "txet/plain",
lastModified: Date.now(),
});
let container = new DataTransfer();
`container.items.add(fileItem);
fileInputElement.files = container.files;`
应用场景 {#menu_index_3}
通过 form
提交自定义的文件:
let container = new DataTransfer();
let file = new File([blob], 'tp_tmp.zip');
let frame = document.createElement('iframe');
let form = document.createElement('form');
let input = document.createElement('input');
container.items.add(file);
frame.setAttribute('name', 'form-result');
form.setAttribute('action', `http://${localDeviceIP}:10808/ProcessServer/FileOperate/fileUpServlet`);
form.setAttribute('enctype', 'multipart/form-data');
form.setAttribute('method', 'post');
form.setAttribute('target', 'form-result');
form.appendChild(input);
input.setAttribute('name', 'file');
input.setAttribute('type', 'file');
input.files = container.files;
document.body.appendChild(frame);
document.body.appendChild(form);
`form.submit();`