I am looking to rename (or move) my S3 objects, I have their URLs like https://s3.eu-west-2.amazonaws.com/sample-bucket/temp/sample-picture.jpg
Is there any standard way in Ruby SDK to get Aws::S3::Object by only URL or I have to parse it by regular expression for example ?
In Java SDK there is AmazonS3URI.java
I haven't found any method to just take the s3 url and get the object. I ended up with parsing it by myself.
Related
Goal:
Implement reading Minio objects through signed URLs (using github.com/minio/minio-go/v6)
Attempt:
I followed the example from github:
https://github.com/minio/minio-go/blob/master/examples/s3/presignedgetobject.go
and using PresignedGetObject(), I end up with a net/url struct. When I concatenate the url.Host and url.Path value the result is something like: localhost:9000/inputs/2ea471a5521c.pdb. Which simply links to the object in Minio UI.
I expected the client to generate a signed URL that enables downloading the object when queried with curl or else, something like this in Google Cloud Storage:
https://cloud.google.com/storage/docs/access-control/signed-urls#example
Am I missing some additional logic or have I misinterpreted what minio pre-signed URLs are? Thank you.
If you want the presigned url as string you can simply call
presignedURL.String()
https://golang.org/pkg/net/url/#URL.String
I'm looking to move from version 1 of the AWS SDK for Ruby to version 2. However I've hit a snag with S3 object versioning.
Given a reference to an S3 object in Version 1 of the API you could retrieve all versions of just that object: http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/S3/S3Object.html#versions-instance_method
However Version 2 of the API does not seem to replicate this feature: http://docs.aws.amazon.com/sdkforruby/api/Aws/S3/Object.html
Am I missing something?
I think you're correct, and this feature is missing from the V2 API. I believe your only options are bucket.object_versions or client.list_object_versions.
You can retrieve all versions of an S3 object from the bucket like this:
# Retrieve Collection<ObjectVersion>
Aws::S3::Bucket.new('bucket-name')
.object_versions(prefix: 'object-key')
.reject { |version| version.key != 'object-key' }
I would guess that the Ruby SDK has made this change to better reflect the S3 REST API, where versions is its own subresource and objects don't have any knowledge of their own version history.
I'm making an upload form for zips in a ruby webmachine app. My idea is to have an upload through my backend where I can add some extra params and then upload it to amazons s3 service with RestClient.
I did successfully create a direct upload (web based form post) to a s3bucket, but in that way I'm unable to handle the variables which are needed in the request, the way I want.
I've tried several things but I can't figure out, how to handle the request, as soon as it gets in my backend. I've created a resource and I'm debugging directly in the process_post method.
My #request variable represents a Webmachine::Request, with a Webmachine::Adapters::Rack::RequestBody and a Rack::Request, but I can't get the file out of it to use it as input for my RestClient request.
I think; #request.body.to_s and #request.body.to_io, represent the uploaded file in some way, and I tried to use them as input for Rack::Multipart methods, but that doesn't give me the file.
I also tried to work with the rack-raw-upload gem, but I can't get the mime-type something else than "application/x-www-form-urlencoded" or multipart. I do explicitly set it to; application/octet-stream
Things like File.new(filename, 'rb') gave me `rrno::ENOENT: No such file or directory # rb_sysopen'. For filename I just used 'example.zip'.
I guess I'm missing something which has to do with the Rack::Request call(env) method.
Does somebody have an idea, on how to handle the Rack uploads? Or give me any hints for a new direction? Thanks.
I've created a gist which shows how to retrieve the multipart stream. You'll need further parsing in order to get the uploaded file.
https://gist.github.com/jewilmeer/eb40abd665b70f53e6eb60801de24342
I want to upload a file to S3 using a pre-signed url
First I create a signed url using url_for(:write)
s3object = S3.buckets['myBucket'].objects['someFolder/testFile.txt']
url = s3object.url_for(:write) #
And I get the url as expected.
https://s3.amazonaws.com/myBucket/someFolder/testFile.txt?AWSAccessKeyId=AKJFGKJASGK......
But now I want to upload something using this url
I's assume that there is a way to get an s3 object from that url on which I can use the 'write' method.
Something like obj = getObjectFromUrl(url)
Is there such a method?
If not, how should I use this url to upload something to s3?
EDIT: I probably should explain.
I create the URL for testing sake.
When I will be working on it, I will only have the URL.
Using the URL alone, I will have to upload a file.
Via the current AWS SDK documentation for Ruby, the suggested method is to simply call read on your s3 object. If you already have the s3 object, you should be able to read directly from the object itself. Also, there is a method for streaming downloads if you wish to stream a file read. AWS S3 Object Documentation
obj.write('abc')
puts obj.read
#=> abc
I'm using Dropbox Ruby SDK, now I want get a full length share url of folder instead of the short url method shares(path) returns. But I couldn't find a way to pass query parameter 'short_url=false'( found on core API) with the method, since it only accepts one argument which is the path to share.
The reason I want the full length url is that I need to provide user a direct link to download the files( by adding 'dl=1'to the full url).
Any suggestion is appreciated.
It doesn't look like the Ruby library currently exposes this. But the source code is here: https://github.com/dropbox/dropbox-sdk-ruby/blob/master/lib/dropbox_sdk.rb#L1222-L1225. If you're up for it, please submit a pull request to add this to the SDK.
In the meantime, here's standalone code to do this:
def long_share_url(access_token, path)
client = DropboxClient.new(access_token)
session = DropboxOAuth2Session.new(access_token, nil)
response = session.do_get "/shares/auto/#{client.format_path(path)}", {"short_url"=>false}
Dropbox::parse_response(response)
end