muxinc / upchunk

Uploads Chunks! Takes big files, splits them up, then uploads each one with care (and PUT requests).
MIT License
329 stars 46 forks source link

Multiple uploads #109

Closed florianmascaro closed 4 months ago

florianmascaro commented 1 year ago

Is the a way to upload multiples files at the same time with UpChunk.createUpload of a Direct uploads and not just the files[0] ?

here is my code :

const handleUpload = async (inputRef) => {
    try {
      const upload = UpChunk.createUpload({
        endpoint: createUpload, // Authenticated url
        file: inputRef.files[0], // File object with your video file’s properties
        chunkSize: 5120, // Uploads the file in ~5mb chunks
      });

      // Subscribe to events
      upload.on("error", (error) => {
        setStatusMessage(error.detail);
      });

      upload.on("progress", (progress) => {
        console.log("progress", progress.detail);
        setProgress(progress.detail);
      });

      upload.on("success", () => {
        setStatusMessage("Wrap it up, we're done here. 👋");
      });
    } catch (error) {
      console.log("error", error);
      setErrorMessage(error);
    }
  };
jaredsmith commented 1 year ago

Today, it's not possible to upload multiple files at a time directly with the upchunk library.

florianmascaro commented 1 year ago

Thank you for your answer. I hope it will be possible soon.

Yavari commented 9 months ago

Why not used loop trough the files and call UpChunk.createUpload for each file?

const picker = document.getElementById('picker');
picker.onchange = () => {
    for (var i = 0; i < picker.files.length; i++) {
        const file = picker.files[i];
        const upload = UpChunk.createUpload({
            endpoint: '/upload/' + file.name,
            file,
            chunkSize: 30720,
            dynamicChunkSize: false,
        });

        // subscribe to events
        upload.on('error', err => {
            console.error(`${file.name}: It all went wrong!`, err.detail);
        });

        upload.on('progress', ({ detail: progress }) => {
            console.log(`${file.name}: Progress: ${progress}%`);
        });

        upload.on('attempt', ({ detail }) => {
            console.log(`${file.name}: There was an attempt!`, detail);
        });

        upload.on('attemptFailure', ({ detail }) => {
            console.log(`${file.name}: The attempt failed!`, detail);
        });

        upload.on('chunkSuccess', ({ detail }) => {
            console.log(`${file.name}: Chunk successfully uploaded!`, detail);
        });

        upload.on('success', () => {
            console.log(`${file.name}: We did it!`);
        });
    }
};
cjpillsbury commented 4 months ago

Closing due to inactivity. The suggestion from @Yavari should be sufficient to solve issue with current upchunk architecture (thank you!). Can reopen or create a new issue if needed.