react js handling file upload

后端 未结 7 954
长发绾君心
长发绾君心 2020-12-09 11:29

I\'m new to react js. I want to upload image asynchronously with react js Suppose I have this code

var FormBox = React.createClass({
  getInitialState: funct         


        
7条回答
  •  半阙折子戏
    2020-12-09 12:04

    You can use React Dropzone Uploader, which gives you a dropzone that shows file previews (including image thumbnails) for dropped or chosen files, and also handles uploads for you.

    import 'react-dropzone-uploader/dist/styles.css'
    import Dropzone from 'react-dropzone-uploader'
    
    const Uploader = () => {  
      return (
         ({ url: 'https://httpbin.org/post' })} // specify upload params and url for your files
          onChangeStatus={({ meta, file }, status) => { console.log(status, meta, file) }}
          onSubmit={(files) => { console.log(files.map(f => f.meta)) }}
          accept="image/*,audio/*,video/*"
        />
      )
    }
    

    Uploads have progress indicators, and they can be cancelled or restarted. The UI is totally customizable, and the library has no dependencies.

    Full disclosure: I wrote this library.

提交回复
热议问题