-
Notifications
You must be signed in to change notification settings - Fork 275
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
default_url_options host is not used with restore_cached_data #100
Comments
What is the S3 URL without any URL options? Because to me this error looks like it's trying to connect to https on localhost, not Amazon S3. Could you post here you The For that reason, Note that if you need Shrine::Storage::S3.new(endpoint: "http://my-different-host.com", **s3_options) |
Yes we are using
This allows us to use a fake s3 bucket on local without having to worry about amazon buckets when doing development. I saw that the restore_cached_data does not deal with the url but the url that gets to the extract_metadata method does not have a https and my wonder is if this has anything to do with the shrine gem or the fastimage gem that tries to extract the meta from the file to make sure it's the right one after upload. |
@Chocksy Thanks for the details! I'm trying to reproduce it now, but with no success. Here is my attempt (a self-contained file), maybe you could try to see if you can find anything that is different, and try to reproduce the bug using this script: require "shrine"
require "shrine/storage/s3"
s3_options = {
region: 'us-east-1',
bucket: 'bucket',
access_key_id: '123',
secret_access_key: 'abc',
endpoint: 'http://localhost:10001',
force_path_style: true,
}
Shrine.storages = {
cache: Shrine::Storage::S3.new(prefix: 'shrine/cache', upload_options: { acl: 'public-read' }, **s3_options),
store: Shrine::Storage::S3.new(prefix: 'shrine/store', upload_options: { acl: 'public-read' }, **s3_options),
}
Shrine.plugin :restore_cached_data
Shrine.plugin :determine_mime_type
class ImageUploader < Shrine
end
uploader = ImageUploader.new(:cache)
cached_file = uploader.upload(File.open(__FILE__))
cached_file.metadata["mime_type"] = "fake/mime"
class User
attr_accessor :avatar_data
include ImageUploader[:avatar]
end
user = User.new
user.avatar = cached_file.to_json # restore_cached_data kicks in and corrects MIME type
puts user.avatar.mime_type # outputs the correct "text/x-ruby" When I was thinking about the possible reasons for your error, the only thing that came to mind was that |
What would be most useful is to add a |
It seems like the url is like this: I'm not sure why it would add https there though. |
I need the url method to call this The options in the s3#url method doesn't seem to be open for me though. |
@Chocksy Thank you for diving into this and determining the problem. You are right, you cannot configure And this is coincidentally something for which I've already submitted a fix almost a year ago (aws/aws-sdk-ruby#1027), which seems to have been applied since version 2.2.25 of aws-sdk gem. I'm betting that you're running an older version of aws-sdk, let me know if upgrading fixes it. |
@janko yep that seems to be the issue. Thank you for your help. I'll close this now. So as a summary: |
When using restore_cached_data plugin the default_url_options host seems to not be used. The
extract_metadata
method in store_dimentions raises an error.The error is because we define the host attribute without https but it seems like extract_metadata tries to call it via https.
The only way to make this work is if we set the host attribute to the Shrine::Storage::S3 but that raises a warning that it is deprecated. Only setting the default_url_options is not enough.
The text was updated successfully, but these errors were encountered: