当我尝试将文件上传到我的服务器时,当我选择文件时它就像一个魅力,但当我使用<input type="file" />
时它发送一个空(0字节)文件cordova-plugin-file
。你猜怎么着?
问问题
463 次
1 回答
1
new File
如果您加载,则不会创建相同的对象cordova-plugin-file
。因为window.File
被cordova-plugin-file
.
所以我不得不做一个小技巧(感谢https://stackoverflow.com/a/29390393/178575):
const getFile = dirEntry =>
new Promise((resolve, reject) => {
dirEntry.file(file => {
// window.File is modified by cordova, so we need this trick
const reader = new FileReader()
reader.onloadend = function() {
const blob = new Blob([new Uint8Array(this.result)], {
type: file.type
})
blob.name = file.name
blob.lastModifiedDate = new Date(file.lastModifiedDate)
resolve(blob)
}
reader.readAsArrayBuffer(file)
})
})
于 2018-04-17T17:42:52.350 回答