我正在尝试使用react-dropzone并且我正在尝试读取已拖入该区域的文件夹的所有图像。
我看到他们有一个例子。
const { getDroppedOrSelectedFiles } = require('html5-file-selector')
class FolderDropzone extends React.Component {
constructor() {
super()
this.state = { files: [] }
}
onDrop(files) {
this.setState({
files
})
}
render() {
return (
<section>
<div className="dropzone">
<Dropzone
getDataTransferItems={evt => getDroppedOrSelectedFiles(evt).then(files => files)}
onDrop={this.onDrop.bind(this)}
>
<p>Drop a folder with files here.</p>
</Dropzone>
</div>
<aside>
<h2>Dropped files and folders</h2>
<ul>
{this.state.files.map(f => (
<li key={f.name}>
{f.fullPath} - {f.size} bytes
</li>
))}
</ul>
</aside>
</section>
)
}
}
但它似乎不起作用,也没有说明使用了哪个 3rd 方插件。
我的本地副本收到此错误
index.js:249 Failed to generate preview for file {fileObject: File(180093), fullPath: "1.jpeg", lastModified: 1538421964806, lastModifiedDate: Mon Oct 01 2018 12:26:04 GMT-0700 (Pacific Daylight Time), name: "1.jpeg", …} TypeError: Failed to execute 'createObjectURL' on 'URL': No function was found that matched the signature provided.
at index.js:246
at Array.forEach (<anonymous>)
at index.js:243
fileList.forEach(function (file) {
if (!disablePreview) {
try {
file.preview = window.URL.createObjectURL(file); // eslint-disable-line no-param-reassign
} catch (err) {
if (process.env.NODE_ENV !== 'production') {
console.error('Failed to generate preview for file', file, err); // eslint-disable-line no-console
}
}
}