鍍金池/ 問答/Java  網(wǎng)絡(luò)安全/ 為什么`formdata.append()`第二個參數(shù)可以穿對象?

為什么`formdata.append()`第二個參數(shù)可以穿對象?

場景: 通過攝像機獲取到了的圖片信息為包含rui的數(shù)據(jù), 要進行文件上傳, 百度到的代碼是:

 let formData = new FormData()
    let file = {uri: response.uri, type: 'multipart/form-data', name: 'image.png'}
    formData.append("files",file)

而在文檔中看到的是:

formData.append(name, value, filename)

value
The field's value. This can be a USVString or Blob (including
subclasses such as File).

文檔提到參數(shù)是USVString或者Blob, 那么為什么可以使用一個包含文件信息的對象來代替?

回答
編輯回答
萌面人

可以打印一下file,其實就是一個js對象

console.log(document.querySelector('input[type=file]').files[0])
2017年7月11日 08:31