0

I have a rails app that's connected to my AWS s3 bucket.

I'm trying to simply list all object keys only. But for some reason my code is not JUST returning the object key (the file name) but it's returning all data bout the object.

How do I get just key to print?

And second part of question, should I be placing this code in the view? I am placing this in my index.html.erb file

<% 

s3 = Aws::S3::Client.new(region: 'us-east-2') 
results = s3.list_objects(bucket: 'carbonlite', max_keys: 2) 

%>

<%= results.contents.each do |object| %>
<%   puts "Name: #{object.key}" %>
<% end %>

And I'm getting something like this:

[ ... Aws::S3::Types::Object key="final marty.jpg", last_modified=2020-04-04 22:45:36 UTC, etag="\"07e2b0175fff3c73fe331090c6d6d10d\"", size=651860 ....]

Instead of just

final marty.jpg

Second party of question: Should I be doing this in the view in erb tags like this? If there is better way to handle please advise.

Wes Creations
  • 337
  • 2
  • 10

1 Answers1

0

Sorry I was being daft. I didn't need the puts. Same code just without the puts did the trick.

Wes Creations
  • 337
  • 2
  • 10