amazon web services - Rails AWS S3: Downloading File and Storing in Temp Folder -
I am trying to download a file from my AWS bucket and store it in my temporary folder.
Code below gives this error.
The file name, extension, including the @filename bucket, is the form of a string
S3 = AWS :: S3.new (: access_key_id = & gt; ENV ["AWS_ACCESS_KEY_ID"] ,: secret_access_key => ENV ["AWS_SECRET_ACCESS_KEY"]) bucket = S3.buckets ["name_of_bucket"] File.open (Rails.root.join ("tmp", @ filename), "wb ") File. open file.write. (BUCKET.objects [@filename] .url_for (read)) read the end Here's what I found out:
The first bucket call returns the right thing; the second return puts the BUCKET.objects ['name_of_bucket'] BUCKET.objects ['name_of_bucket'] url_for puts it: https://ekohotstorage.s3-us-west-2.amazonaws.com/location_info what you returned when you visited that URL
The bucket you are attempting to access must be addressed using specified endpoint. Please send all future requests to this ending point. It says "S3 has a limit, so if you make a bucket that is not" US Standard ", then you use path-style syntax in the bucket address. can not do."
However, I checked this bucket and it's def area US standard.
Edit:
I'm stupid; I had read that AWS was the default American standard. But the west is not standard, the former is so I think it is not the default for the American standard. After fixing that stupidity with <3>
S3 = AWS :: S3.new (: access_key_id => ENV ["AWS_ACCESS_KEY_ID"] ,: secret_access_key = & Gt; ENV ["AWS_SECRET_ACCESS_KEY"] ,: Area => "We Pre-1") I'm getting this error now: OpenURI :: HTTPError (404 not found) However, the URL sound file created with the code below
BUCKET. Objects ['name_of_bucket'] url_for .. (Read: then the issue will lie
files Open (Rails.root.join ("tmp", @ filename), "wb") file. open file.write? (BUCKET.objects [@filename] .url_for (read)) read the end idea
Two things start happening here First of all, the American standard area is actually Virginia or Oregon, you just have to realize that you are being redirected because Amazon chose Oregon for its bucket. The URL to be located in the area is currently here:
Another thing is going on redirection. When you are connected, you are being redirected to Oregon because you'll see the general S3 endpoint that the latency is the closest one by the DNS. When you see hard codes later in Virginia, you do not see your bucket in Oregon.
Some of the Amazon documents are here that how S3 will redirect you and how to handle it.
Since you are using Toolkit and instead of APIs, I have not seen anything special in Ruby Forge or Amazon document which will explain why not follow redirection has gone. It seems that other people with ADWS Ruby SDK were about this problem last year. It can be fixed in new versions.
The document I am referring to is here:
The latest documentation appears in Amazon:
The other thing is that I have seen complaints that the redirect URL was corrupted. While I was not able to duplicate that behavior, I try to send a request to the Oregon endpoint that it resolves your problem.
Comments
Post a Comment