首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >react-dropzone -如何通过文件夹读取文件?

react-dropzone -如何通过文件夹读取文件?
EN

Stack Overflow用户
提问于 2018-10-03 23:53:45
回答 1查看 1.5K关注 0票数 0

我正在尝试使用react-dropzone,并且正在尝试读取已被拖入区域的文件夹的所有图像。

我看到他们有一个example

代码语言:javascript
复制
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>
    )
  }
}

但它似乎不工作,也没有说明使用了哪个第三方插件。

我的本地副本收到此错误

代码语言:javascript
复制
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
              }
            }
          }
EN

回答 1

Stack Overflow用户

发布于 2019-08-06 20:25:49

我有这个确切的需求,就像我使用使用rc-uploadantd一样简单。它的工作方式非常出色,您还可以获得所允许的文件类型的相对路径。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52631122

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档