Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't resume uploads! #121

Closed
ghost opened this issue Aug 6, 2018 · 14 comments
Closed

Can't resume uploads! #121

ghost opened this issue Aug 6, 2018 · 14 comments

Comments

@ghost
Copy link

ghost commented Aug 6, 2018

I am developing a website using Laravel, and I am using tus-js-client to upload files directly to Vimeo without going through my server. The uploading works perfect.

But, lets say the uploading reached 44%, and then the user refreshed the browser... as I understand It should continue uploading from 44% when the user start uploading the same file again.. but that doesn't happen!

  // Create a new tus upload
  var self = this;
  // Send request to server to get uploadUrl endpoint from Vimeo api
  var uploadEndPoint = self.getUploadEndPoint();
  // Start uploading
  self.uploader = new tus.Upload(file, {
    uploadUrl: uploadEndPoint,
    retryDelays: [0, 1000, 3000, 5000],
    metadata: {
      filename: file.name,
      filetype: file.type
    },
    resume: true,
    uploadSize: file.size,
    onError: function(error) {
      console.log("Failed because: " + error);
    },
    onProgress: function(bytesUploaded, bytesTotal) {
      var percentage = (bytesUploaded / bytesTotal * 100).toFixed(2);
      console.log(bytesUploaded, bytesTotal, percentage + "%");
    },
    onSuccess: function() {
      console.log(
        "Download %s from %s",
        self.uploader.file.name,
        self.uploader.url
      );
    }
  });
@Acconut
Copy link
Member

Acconut commented Aug 6, 2018

But, lets say the uploading reached 44%, and then the user refreshed the browser... as I understand It should continue uploading from 44% when the user start uploading the same file again.. but that doesn't happen!

That's how it should behave, you are right. What is happening instead?

@ghost
Copy link
Author

ghost commented Aug 6, 2018

That's how it should behave, you are right. What is happening instead?

It starts uploading the file from the beginning as a new upload.

@ghost
Copy link
Author

ghost commented Aug 6, 2018

I think this is happening because when I send an API request to Vimeo to get an uploadUrl endpoint It will give me a new uploadUrl endpoint when the user refresh the page..

@Acconut
Copy link
Member

Acconut commented Aug 7, 2018

I think this is happening because when I send an API request to Vimeo to get an uploadUrl endpoint It will give me a new uploadUrl endpoint when the user refresh the page..

That seems to be the likely cause as far as I can tell.

@ghost
Copy link
Author

ghost commented Aug 7, 2018

but isn't this the "resume = true" job? as I understand:

User was uploading a file then when it reached 44%, the user refreshed the page, then the user re-upload the same file again:
1 - check if the file object is stored in the storage (using fingerprint unique string).
2 - if the file is there (fingerprint) get the uploadUrl to resume the upload for the same file to the previous uploadUrl endpoint.

Is this right?

If it is, Is there a way to check if the (fingerprint) for the file exist?

@Acconut
Copy link
Member

Acconut commented Aug 7, 2018

but isn't this the "resume = true" job?

Not in this case. If you supply a uploadUrl, tus-js-client will resume using this URL even if the file has been uploaded to some other URL before. This fact is also stated in the documentation:

uploadUrl = null: a URL which will be used to directly attempt a resume without generating the fingerprint and looking it up before.

However, if no uploadUrl is given, you would be correct.

Is there a way to check if the (fingerprint) for the file exist?

No, there is currently no way to do so.

@ghost
Copy link
Author

ghost commented Aug 7, 2018

Thank you for your help, I have solved the issue using server-side cache.

@Acconut
Copy link
Member

Acconut commented Aug 7, 2018

You're welcome :)

@Acconut Acconut closed this as completed Aug 7, 2018
@mahmudul
Copy link

mahmudul commented Apr 21, 2019

Hi @Acconut, pretty same issue I am facing for couple of days. In my case, when I click on resume for a paused upload, it begins from the start. I checked the solution that 'ghost' resolved by. I am using file based cache in server-side where I have .cache/ folder having 'tus_php.server.cache' file. A sample entryin the cache file looks like when I click pause:

"tus:server:41b5c307-a9c5-406a-8a3a-a2335732ecf4":{"name":"IMG_0045.JPG","size":2078503,"offset":0,"checksum":"","location":"http://example.com/files/41b5c307-a9c5-406a-8a3a-a2335732ecf4","file_path":"/var/www/vhosts/example.com/uppy/uploads/IMG_0045.JPG","created_at":"Sun, 21 Apr 2019 05:53:01 GMT","expires_at":"Mon, 22 Apr 2019 05:53:01 GMT","upload_type":"normal"}}

Once it is uploaded without any pause, the cache file looks like:

"tus:server:41b5c307-a9c5-406a-8a3a-a2335732ecf4":{"offset":2078503,"name":"IMG_0045.JPG","size":2078503,"checksum":"","location":"http://example.com/files/41b5c307-a9c5-406a-8a3a-a2335732ecf4","file_path":"/var/www/vhosts/example.com/uppy/uploads/IMG_0045.JPG","created_at":"Sun, 21 Apr 2019 05:53:01 GMT","expires_at":"Mon, 22 Apr 2019 05:53:01 GMT","upload_type":"normal"}}

Only the offset has been changed. If I am missing anything on the server side cache settings. I am using tus-js-client at client side. Here is the Tus config at client:

   .use(Tus, {
              endpoint: '/files/', // use your tus endpoint here

	  resume: true,

	  autoRetry: true,

	  retryDelays: [0, 1000, 3000, 5000]

	})

Thanks in advance.

@Acconut
Copy link
Member

Acconut commented Apr 24, 2019

@mahmudul I don't see an inherent problem with your configuration but it might be caused by tus_php, which I have never used personally. Does the problem persist if you use https://master.tus.io/files/ (notice the trailing slash) as the endpoint? If the problem vanishes we know that is likely caused by the server and not by tus-js-client. Also what environment are you in? I would assume the browser, right?

@mahmudul
Copy link

Hi @Acconut, thanks for your reply. Yes I am using browser and https://master.tus.io/files/ is working fine as Tus endpoint. It also works well in my local pc environment using file cache. So, it should be server side issue. I can see that the file opcache is disabled in the server and suspecting that could be the cause. Though it's not a tus-js-client issue, may I ask you whether enabling opcache could resolve the issue? I am hopeful but not sure 100%.

@Acconut
Copy link
Member

Acconut commented Apr 25, 2019

So, it should be server side issue.

Yes, I agree with that.

I can see that the file opcache is disabled in the server and suspecting that could be the cause. Though it's not a tus-js-client issue, may I ask you whether enabling opcache could resolve the issue?

Frankly, I don't know. I have never used tus_php and my PHP knowledge does not include opcache. So I can't help you there and would recommend that you just give it a try.

@mahmudul
Copy link

Thanks @Acconut for your time on this. I'll have a try. I have opened an issue at tus-php that I am using as tus server. May be the owner could provide some insights.
Cheers.

@aqib008

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants