janko / uppy-s3_multipart

Provides Ruby endpoints for AWS S3 multipart uploads in Uppy
https://uppy.io/docs/aws-s3/
MIT License
65 stars 21 forks source link

Integration Issue #5

Closed parwatcodes closed 5 years ago

parwatcodes commented 5 years ago

I am trying to use this plugin in my rails app.

As per the docs.

config/initializers/shrine.rb

not sure should i name it shrine.rb or uppy-s3_multipart.rb

require "shrine"
require "shrine/storage/s3"

s3_options = {
    access_key_id:     'XXXXX-XXXXX-XXXXX',
    secret_access_key: 'XXXXX-XXXXXX-XXXXXX-XXXXXX',
    region:            'us-east-2',
    bucket:            'my-bucket',
  }

Shrine.storages = {
    cache: Shrine::Storage::S3.new(prefix: "cache", **s3_options),
    store: Shrine::Storage::S3.new(**s3_options),
}

Shrine.plugin :uppy_s3_multipart

config/routes.rb

Rails.application.routes.draw do
  mount Shrine.uppy_s3_multipart(:cache) => "/s3"
end

Running rails routes command doesn't list the routes. It shows

screen shot 2018-12-05 at 4 44 00 pm

janko commented 5 years ago

not sure should i name it shrine.rb or uppy-s3_multipart.rb

You can name Rails initializers whatever you want 😉. In this case shrine.rb makes sense to me, because you're configuring Shrine.

Running rails routes command doesn't list the routes:

That's expected. Rails will only lists routes for Rails engines, because those define their routes via the Rails router. Uppy::S3Multipart::App is just an object that responds to #call and returns a response based on request information (= a rack app). Rails doesn't know how it does the routing internally, because it doesn't use Rails routing for that.

If Rails provided a mechanism for Rack apps to declare their routes, then I'd be open to adding support for that in uppy-s3_multipart.

parwatcodes commented 5 years ago

What I am trying to achieve is

  1. I am using uppy client in frontend (React app).
  2. I'll be using aws-s3-multipart uppy plugin to support large files with resumable, which gets upload to s3 bucket.
  3. I'm trying to integrate this, I think i need to make use of companion server suggested as per uppy docs.
  4. How can i achieve that

Please correct me if anything is wrong

janko commented 5 years ago

How can i achieve that

You now just need to point Uppy's serverUrl to your Rails app, as per the README. Are you encountering any problems with that?

I think you misunderstood my last comment. Uppy::S3Multipart::App still adds the /s3/multipart/* routes and they should work. Rails is only not displaying them in rake routes, but that doesn't mean they're not there.

parwatcodes commented 5 years ago

Oh. Can you tell me how to implement whole flow work on ruby server. (resumable upload to s3

Let's assume I made the routes and initializers setup. Now, what further steps should I need to follow

  1. Client will send the video
  2. VIdeo has to be uploaded to the s3 bucket, after the successful update, I will update the certain DB row with uploaded URL.

I'm pretty new to rails. Any help is highly appreciated.

janko commented 5 years ago

With the routes and initializers setup (and S3 bucket setup of course), clients should now be able to successfully upload the video.

Once the upload finishes, you can attach it with Shrine like with any other kind of direct upload. See this wiki page for a complete example. It's using Roda and regular S3 upload, but it should be easy to translate to Rails. There is also a Rails demo app linked in the Shrine README.

Note that uppy-s3_multipart is only in charge of the client side upload to S3, everything else is regular Shrine, so you should look at the Shrine documentation for how to attach directly uploaded files.