Daniel Fischer
Daniel Fischer

Reputation: 3062

Uploading an image in Rails on Heroku to Imgur via API

Is it possible to upload an image using imgur's api via Rails on Heroku (write limitability?)

I was looking at the following gem:

https://github.com/vanntastic/imgur

How would you handle the actual process of pointing to the actual file to upload with the upload_file method?

Upvotes: 1

Views: 1655

Answers (3)

Nossidge
Nossidge

Reputation: 961

Perhaps the API has changed over the 6 years since this question was posted, but neither of these methods worked for me in mid-2018.

The solution I used is the 'imgur-api' gem. Sample code below:

require 'imgur'

client_id = '1ae88df00f00f00' 

client = Imgur.new(client_id)

image = Imgur::LocalImage.new('test.png', title: 'Test image')

uploaded = client.upload(image)

puts uploaded.link
#=> https://i.imgur.com/bBlMW3X.png

Upvotes: 0

Trevoke
Trevoke

Reputation: 4117

Long time no speak.

I literally JUST implemented this: github commit diff. In my case, since imgur returns a string called 'image_hash' as well as a bunch of other things, I just implemented how to rederive all the other stuff and only stored that small string. I hope this helps! I should consider making this into a full-fledged Rails gem.

[Edit - the code is not perfect, it's version 1!]

Upvotes: 0

shingara
shingara

Reputation: 46914

You can do that, because you have access to tmp directory. When a file is download on this tmp directory.

Upvotes: 1

Related Questions