GithubHelp home page GithubHelp logo

Comments (4)

hossein-zare avatar hossein-zare commented on September 14, 2024

Hello,

Please send me your code.
Most likely you've been using it in a functional component.

from react-native-chunk-upload.

hosein-yarzade avatar hosein-yarzade commented on September 14, 2024
class App extends Component {

  constructor() {
    super();
    this.state = {
      videoFile: {},
    };
  }

  sendVideo = () => {

    const chunk = new ChunkUpload({

      path: this.state.videoFile.path, // Path to the file
      size: 10024, // Chunk size (must be multiples of 3)
      fileName: this.state.videoFile.fileName, // Original file name
      fileSize: this.state.videoFile.size, // Original file size
      // Errors
      onFetchBlobError: (e) => console.log(e),
      onWriteFileError: (e) => console.log(e),
    });
    chunk.digIn(this.upload.bind(this));

  upload(file, next, retry, unlink) {

    const body = new FormData();

    body.append('video', file.blob); // param name
    Axios.post('vod/submitStep1', body, {

        headers: {
          'Content-Type': 'multipart/form-data',
          Accept: 'application/json',
          'x-chunk-number': file.headers['x-chunk-number'],
          'x-chunk-total-number': file.headers['x-chunk-total-number'],
          'x-chunk-size': file.headers['x-chunk-size'],
          'x-file-name': file.headers['x-file-name'],
          'x-file-size': file.headers['x-file-size'],
          'x-file-identity': file.headers['x-file-identity'],
        },
      })
      .then((response) => {

        switch (response.status) {
          case 200:
            console.log(response.data);
            break;
          case 201:
            console.log(`${response.data.progress}% uploaded...`);
            next();
            break;
        }
      })
      .catch((error) => {

        if (error.response) {

          if ([400, 404, 415, 500, 501].includes(error.response.status)) {

            console.log(error.response.status, 'Failed to upload the chunk.');

            unlink(file.path);

          } else if (error.response.status === 422) {

            console.log('Validation Error', error.response.data);

            unlink(file.path);
          } else {
            console.log('Re-uploading the chunk...');

            retry();
          }
        } else {

          console.log('Re-uploading the chunk...');

          retry();
        }
      });
  }
}

Hello,

Please send me your code.
Most likely you've been using it in a functional component.

here you are

from react-native-chunk-upload.

hossein-zare avatar hossein-zare commented on September 14, 2024

Add a } before the upload function.

sendVideo = () => {
    const chunk = new ChunkUpload({

      path: this.state.videoFile.path, // Path to the file
      size: 10024, // Chunk size (must be multiples of 3)
      fileName: this.state.videoFile.fileName, // Original file name
      fileSize: this.state.videoFile.size, // Original file size
      // Errors
      onFetchBlobError: (e) => console.log(e),
      onWriteFileError: (e) => console.log(e),
    });
    chunk.digIn(this.upload.bind(this));
} // You've forgotten a closing curly brace

from react-native-chunk-upload.

hosein-yarzade avatar hosein-yarzade commented on September 14, 2024

thanks i got it

from react-native-chunk-upload.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.