0

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?

parwatcodes
  • 6,669
  • 5
  • 27
  • 39

1 Answers1

1

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.

Janko
  • 8,985
  • 7
  • 34
  • 51
  • ATM I won't be dealing with approach A. Approach B might be what I am looking for. If I implement direct upload to Vimeo from clientside, I need to look after success or error response sent from the Vimeo and send an API request to the mine server and update the video table with Vimeo `data_url` if the response is a success. – parwatcodes Nov 26 '18 at 05:45
  • ATM I'm not dealing with Oauth. I'll just use the public `access_token` from vimeo and every user can upload videos in mine account. (No oauth req.). I looked at [vimeo-uppy-thing](https://github.com/transloadit/uppy-vimeo-thing/blob/master/app.js). It involves whole oauth procedure and I even didn't get much of it. What mine concern is user selects the video from uppy dashboard clicks the Upload button video gets uploaded to Vimeo. That's it (no oauth). – parwatcodes Nov 26 '18 at 05:49
  • To my knowledge these are the only two solutions with acceptable performance, and both are implementable. – Janko Nov 26 '18 at 11:59
  • So, if I need to upload videos to AWS s3 bucket. What approaches should I take? Using uppy `aws s3 multipart` plugin. – parwatcodes Dec 05 '18 at 08:04
  • Docs say that i need to create an companion server for that? – parwatcodes Dec 05 '18 at 08:05
  • You can use either `aws s3 multipart` or `tus` Uppy plugin, whichever one you prefer. For `aws s3 multipart` approach you can either use Uppy's Companion (Node app) or the [uppy-s3_multipart](https://github.com/janko-m/uppy-s3_multipart) Ruby gem, while for `tus` approach you can use the official [tusd](https://github.com/tus/tusd) server (Go app), or [tus-ruby-server](https://github.com/janko-m/tus-ruby-server) that's written in Ruby. – Janko Dec 05 '18 at 12:52