javascriptruby-on-railsshrinetus

Tus server Integration with shrine "Dealing with large uploads filesize > 1 gb"


I am trying to integrate the tus-server with shrine to upload the video files to Vimeo.

Client.js

this.uppy = new Uppy({
  id: 'uppy1',
  autoProceed: false,
  debug: true,
  restrictions: {
    allowedFileTypes: ['.mp4'],
  },
  allowMultipleUploads: true,
})
  .use(Tus, { endpoint: `${API_BASE}/files` })
 /* .use(XHRUpload, { endpoint: `${API_BASE}/files`,
    formData: true,
    bundle: false,
    fieldName: 'file',
    headers: getHeaders(), */
 })
  .use(GoogleDrive, { serverUrl: 'https://companion.uppy.io' })
  .use(Dropbox, { serverUrl: 'https://companion.uppy.io/' });

# config/routes.rb (Rails)
Rails.application.routes.draw do
  mount Tus::Server => "/files"
end

Here, by default, the server directly uploads the file to the data/ folder with a file in the project root.

What I want to achieve is to upload the video files to Vimeo.

Like:

  1. File goes to ${API_BASE}/files
  2. Mine controller gets the file
  3. I pass the file to Vimeo (using vimeo_me2)
  4. Vimeo uploads the file and sends the video_url back. I now insert the video_url in a certain video table.
  5. All these above processes need to be resumable.

I am using vimeo_me2 gem.

Can Anyone provide a solution to integrate/configure Tus server with Shrine?


Solution

  • Author of tus-ruby-server and Shrine here :)

    You have two options as far as I'm concerned: use Vimeo's "pull upload", or upload directly to Vimeo.

    A. Pull upload

    Vimeo's pull upload allows you to give Vimeo the link to your file, and let it download and save the file for you. This should be resumable, because tus-ruby-server supports range requests, and it seems that Vimeo will use that:

    We even handle any connectivity issues that might come up.

    The vimeo_me2 gem has a method for pull upload. So you can just give it the link to the tus file, e.g if you have a Movie with a video attachment:

    vimeo_client.pull_upload("Name of video", movie.video.url)
    

    B. Direct upload to Vimeo

    Vimeo also implements the tus resumable upload protocol, so theoretically it should be possible to use Uppy to upload directly to Vimeo. In that case you could get rid of tus-ruby-server.

    I haven't personally tried this approach. It seems like there is an extra first step of creating the video, but the rest of it looks like the standard tus protocol. These is an example app created by the authors of Uppy, so I think you should be able to copy-paste a lot of the stuff from there.


    The approach I don't recommend is downloading the file from the tus server and uploading it to Vimeo using the vimeo_me2 gem. Firstly, the download won't be resumable, as the down gem that shrine-tus uses doesn't yet support resumable downloads. Secondly, while vimeo_me2 uses the tus protocol for uploading, it doesn't seem to do anything to resume the upload in case of connection errors. It also appears to load the whole file into memory.

    In any case, options A and B will be more performant.