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

Error on Heroku uploading to an s3 #20

Open
usern3 opened this issue Mar 21, 2021 · 0 comments
Open

Error on Heroku uploading to an s3 #20

usern3 opened this issue Mar 21, 2021 · 0 comments

Comments

@usern3
Copy link

usern3 commented Mar 21, 2021

I'm having rouble uploading on Heroku. heres part of the log, the config, and part of the form.

2021-03-21T02:32:10.850984+00:00 app[web.1]: {"severity":"Error","source":"lucky","timestamp":"2021-03-21T02:32:10+00:00","error":{"class":"Shrine::Error","message":"storage "store" isn't registered on Shrine","backtrace":["/tmp/build_3ef14957/lib/shrine/src/shrine.cr:31:3 in 'find_storage'","/tmp/build_3ef14957/lib/shrine/src/shrine.cr:241:7 in 'upload:metadata'","/tmp/build_3ef14957/lib/shrine/src/shrine.cr:173:7 in 'call'","/tmp/build_3ef14957/lib/lucky/src/lucky/renderable.cr:111:16 in 'perform_action'","/tmp/build_3ef14957/lib/lucky/src/lucky/route_handler.cr:10:7 in 'call'","/tmp/build_3ef14957/.heroku/crystal/share/crystal/src/http/server/handler.cr:28:7 in 'call'","/tmp/build_3ef14957/.heroku/crystal/share/crystal/src/http/server/handler.cr:28:7 in 'call'","/tmp/build_3ef14957/.heroku/crystal/share/crystal/src/http/server/handler.cr:28:7 in 'call'","/tmp/build_3ef14957/.heroku/crystal/share/crystal/src/http/server/handler.cr:28:7 in 'call'","/tmp/build_3ef14957/.heroku/crystal/share/crystal/src/http/server/handler.cr:28:7 in 'call_next'","/tmp/build_3ef14957/lib/lucky/src/lucky/force_ssl_handler.cr:36:8 in 'call'","/tmp/build_3ef14957/.heroku/crystal/share/crystal/src/http/server/request_processor.cr:50:11 in 'process'","/tmp/build_3ef14957/.heroku/crystal/share/crystal/src/http/server.cr:498:5 in '->'","/tmp/build_3ef14957/.heroku/crystal/share/crystal/src/primitives.cr:255:3 in 'run'","???"]}}
2021-03-21T02:32:10.850987+00:00 app[web.1]: {"severity":"Info","source":"lucky","timestamp":"2021-03-21T02:32:10+00:00","local":{"status":500,"duration":"195.49ms"}}
2021-03-21T02:32:10.848941+00:00 heroku[router]: at=info method=POST path="/users/1/edit" host=askcr.io request_id=b971bb4c-32dc-4cc3-8dd5-f6a7ae8da0db fwd="185.99.3.119" dyno=web.1 connect=0ms service=1228ms status=500 bytes=1817 protocol=http

config/shrine.cr

Shrine.configure do |config|
  if Lucky::Env.test?
    config.storages[ShrineStorage::UPLOADS] = Shrine::Storage::Memory.new
  elsif Lucky::Env.development?
    config.storages[ShrineStorage::UPLOADS] = Shrine::Storage::FileSystem.new("tmp", prefix: "assets/uploads")
  else
    client = Awscr::S3::Client.new(ENV["BUCKETEER_AWS_REGION"], ENV["BUCKETEER_AWS_ACCESS_KEY_ID"], ENV["BUCKETEER_AWS_SECRET_ACCESS_KEY"])
    config.storages[ShrineStorage::UPLOADS] = Shrine::Storage::S3.new(bucket: ENV["BUCKETEER_BUCKET_NAME"] , client: client, prefix: "public/upload", public: false)
  end
end

# Defines the `Shrine` storage locations for different data types.
module ShrineStorage
  UPLOADS = "uploads"
end

# TRICKY: we patch this because it's not providing the correct download url
class Shrine
  module Storage
    class S3 < Storage::Base
      def url(id : String, **options) : String
        endpoint : String?
        if ep = csrhine]Zent.@endpoint
          endpoint = ep.gsub("https://", "")
        end
        presigned_options = Awscr::S3::Presigned::Url::Options.new(
          aws_access_key: client.@aws_access_key,
          aws_secret_key: client.@aws_secret_key,
          region: client.@region,
          object: UUID.new.variant.to_s,
          bucket: bucket,
          host_name: endpoint
        )

        url = Awscr::S3::Presigned::Url.new(presigned_options)
        url.for(:get)
      end
    end
  end
end

form code:

  #Shortened for brevity.
  mount ::Shared::Field, op.profile_picture, label_text: "Avatar", &.file_input
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

1 participant