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

I am try to resume upload, but it seems it restart again but no resume. #112

Closed aqib008 closed 10 months ago

aqib008 commented 11 months ago

Lets say I add 100 mb file to upload and after 50 mb network failure occurs, after restoring internet it restart again from very beginning, so we can it's restartable but not resumable. Is it expected behaviour or am i doing something wrong. I believe there is some error in library as it doesn't store any chunk related data to resume.

Here is my code:

  const handleUpload = async (inputRef) => {
        try {
            //   const response = await fetch('https://storage.googleapis.com/resumable/upload/storage/v1/b/picsello-staging/o?uploadType=resumable&name=galleries%2F406%2Foriginal%2Fa12e384d-90a1-4a80-8f3d-977eb1f8244c.jpeg&upload_id=ADPycdt7jXCKxTYrO21tzi80raNAIptB80PdXvAmNVZpXvMMFTTRujiQy8bi6kE9QhmTHsR3PBCF3_8ARByC0-7ZErieeiszZ56x', { method: 'POST' });
            //   const url = await response.text();
            let url = "https://storage.googleapis.com/resumable/upload/storage/v1/b/picsello-staging/o?uploadType=resumable&name=galleries%2F406%2Foriginal%2Fa12e384d-90a1-4a80-8f3d-977eb1f8244c.jpeg&upload_id=ADPycdt7jXCKxTYrO21tzi80raNAIptB80PdXvAmNVZpXvMMFTTRujiQy8bi6kE9QhmTHsR3PBCF3_8ARByC0-7ZErieeiszZ56x"
            uploader = UpChunk.createUpload({
                endpoint: url, // Authenticated url
                file: inputRef.files[0], // File object with your video file’s properties
                chunkSize: 30720, // Uploads the file in ~30 MB chunks
            });

            // Subscribe to events
            uploader.on('error', error => {
                // setStatusMessage(error.detail);
                console.log(error.detail);
            });

            uploader.on('progress', progress => {
                setProgress(progress.detail);
                console.log(progress.detail);
            });

            uploader.on('success', () => {
                // setStatusMessage("Wrap it up, we're done here. 👋");
                console.log("Wrap it up, we're done here. 👋");
            });

            uploader.on('offline', () => {
                console.log("offline");
                uploader.pause()
            });

            uploader.on('online', () => {
                console.log("online");
                uploader.resume()
            });

        // console.log(uploader)
        // setObj(uploader)
        setUploader(uploader)

        } catch (error) {
            //   setErrorMessage(error);
            console.log(error)
        }
    }

Neither it's pause and resume methods are working.

I am using "@mux/upchunk": "^3.2.0",

cjpillsbury commented 11 months ago

Hey @aqib008 I'll be sure to look into this soon. Will keep you posted on any updates.

cjpillsbury commented 11 months ago

Hey @aqib008 I was able to follow up on this. I'm wondering if your issue might be related to you doing manual management of the pause() and resume() at the "app level." Upchunk will automatically take care of halting/resuming uploads whenever a offline/online event is dispatched. I've confirmed locally that this works for me at least. Would you mind trying that and letting me know if that resolves your issue?

cjpillsbury commented 10 months ago

Closing due to inactivity. Happy to re-open if the suggestion above does not resolve the issue.