【问题标题】:Append simple file to input将简单文件附加到输入
【发布时间】:2018-08-16 20:27:12
【问题描述】:

我正在上传 formData,但不知何故,我在标题上使用这个得到了一个空文件

 var formData = new FormData(document.getElementById('creationForm'));
 console.log(file);
 formData.append("fileUpload", file);

当我进行拖放时它不起作用。那么如何将文件附加到creationForm 上的实际输入中呢?

<input type="file" name="fileUpload" id="fileUpload" class="hide"/>

【问题讨论】:

  • 如果我这样做 $('#fileUpload').val(file); 它给我 Failed to set the 'value' property on 'HTMLInputElement': 此输入元素接受一个文件名,该文件名只能以编程方式设置为空字符串。跨度>
  • 一些安全原因。寻找more
  • 那么我该怎么做呢?该文件的 console.log 有该文件,当我将它附加到 formData 时,我得到一个大小为 0 的文件??
  • 这可能会有所帮助:stackoverflow.com/questions/4526273/…

标签: javascript jquery html


【解决方案1】:

不明白拖拽,比如在IE中不能拖拽n drop到输入类型的文件,不过我觉得this的回答可以帮上忙。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-24
    • 2017-03-20
    • 2020-03-12
    相关资源
    最近更新 更多