react-component / react-component/upload

CustomRequest Style won't change no matter if the file is uploaded or not. It will always show file uploading style

Open
#188 1 comment 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
804
Forks
323
Avg merge
12m
Merged PRs (30d)
1

Description

Please see the response here. The first one is with success, the second is with failure.
image

Here is my code.

 state = {
    previewVisible: false,
    previewImage: "",
    fileList: []
  };

handleChange = ({ fileList }) => {
    this.setState({
      fileList: fileList
    });
    console.log(this.state.fileList);
  };

  customUpload = ({
    file,
    onProgress,
    headers,
  }) => {
    const { onSuccess, onError, image_type } = this.props;
    
    if (file.size / 1024 / 1024 > 5) return false;
    else if (imageTypes.indexOf(file.type) < 0) return false;
    else if (!imageTypes) return false;
    else {
      let data = new FormData();
      data.append('image_file',file)
      data.append("image_type", image_type);
      console.log(data);
      
      Axios.post(URL + "image_upload/", 
      data,
      { 
       headers,
        onUploadProgress:({total,loaded}) =>{
          onProgress({ percent: Math.round(loaded / total * 100) }, file)
        }
      })
      .then((res) => {
        onSuccess && onSuccess(res) 
      })
      .catch( err=> {
        onError && onError(err) 
      });
    }
  }


return (
<Upload
          //listType="picture"
          fileList={fileList}
          headers={headers}
          accept={"image/*"}
          customRequest={this.customUpload}
          onPreview={this.handlePreview}
          onChange={this.handleChange}
        >
        </Upload>
)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Upload component's customRequest and fileList handling, using the provided customUpload and handleChange callbacks as the reproduction. Verify how upload success and failure are reflected in the displayed file style, and consider the issue resolved when the style differs correctly for successful and failed uploads.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.