1
 const MyUploader = () => {
    
    const getUploadParams = ({ meta,url }) => {          // specify upload params and url for your files
      console.log("uploadParams",meta,url)
      return { url: '/v1/file_uploads/' }
    }
       
    const handleChangeStatus = ({ meta, file }, status) => {     // called every time a file's `status` changes
      console.log("handleStatus",status, meta, file) 
    }
        
    const handleSubmit = (files, allFiles) => {   // receives array of files that are done uploading when submit button is clicked
      console.log(files.map(f => f.meta))
      allFiles.forEach(f => f.remove())
    }
  
    return (
      <Dropzone
        getUploadParams={getUploadParams}
        onChangeStatus={handleChangeStatus}
        onSubmit={handleSubmit}
        accept="image/*"
      />
    )
  }

<MyUploader />

I'm able to save the uploaded file in the Database, when file is saved i am rendering some information

render json: {status: "Success", blob: blob, url: URL }

How can i console log this data which i am rendering in the React ??

The link of the package is : https://github.com/fortana-co/react-dropzone-uploader

1 Answer 1

1

I have solved the problem by passing xhr as a parameter to handleChangeStatus function.

const MyUploader = () => {
    
    const getUploadParams = ({ meta }) => {          // specify upload params and url for your files
      return { url: '/v1/file_uploads/' }
    }  

    const handleChangeStatus = ({ meta, file,xhr }, status) => {     // called every time a file's `status` changes
      console.log("handleStatus",status, meta, file) 
      if(status == "done") { 
        var json = JSON.parse(xhr.response)
        var arr_blob_ids = state.documents_blob_ids.slice()
        console.log("id added",json.blob.id)
        if (json.blob.id){
          arr_blob_ids.push(json.blob.id)
          setState({...state,documents_blob_ids: arr_blob_ids})
        }
       }

      else if(status == "removed") {
        var json = JSON.parse(xhr.response)
        var arr_blob_ids = state.documents_blob_ids.slice()
        console.log("id removed",json.blob.id)
        if (json.blob.id){
          arr_blob_ids =  arr_blob_ids.filter( v => v!= json.blob.id)
          setState({...state,documents_blob_ids: arr_blob_ids})
        }       
      }
     
    }
        
    const handleSubmit = (files, allFiles) => {   // receives array of files that are done uploading when submit button is clicked
      console.log(files.map(f => f.meta))
      allFiles.forEach(f => f.remove())
    }
  
    return (
      <Dropzone
        getUploadParams={getUploadParams}
        onChangeStatus={handleChangeStatus}
        onSubmit={handleSubmit}
        accept="image/*"    
        submitButtonContent = {null}
        SubmitButtonComponent = {null}    
      />
    )
  }

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.