Hi all I'm using paperclip-dropbox gem >= 1.1.7
paperclip dropbox gem
then here are my attributes:
and in my form:
= f.file_field :avatar
and in my model
has_attached_file :avatar,
:storage => :dropbox,
:dropbox_credentials => Rails.root.join("config/dropbox.yml"),
:dropbox_visibility => 'public'
then when I add an image I can upload the image to dropbox and these attributes has a values avatar_content_type, avatar_file_size, avatar_updated_at but it cannot store the uploaded image url. Please help thanks!
PS. I'm using a non-premium dropbox account and the images we're uploaded in Apps/my_images folder in Dropbox.
You are right. It was not storing uploaded avatar_url. Because in "App folder" access whenever you are calling model_name.avatar.url then it will call dropbox api everytime and generated link from this will be valid for only 4 hours. so you can't store this generated url into database as well as for future use. Here I will explain you about access type in dropbox:
Full Dropbox access
Files will be stored in the Public folder. Download URLs are predictable, valid forever, and don’t require an API call to retrieve, but this may not be a good thing if you don’t want your files to be easily accessed. When using one account to store data for multiple sites (e.g. staging and production instances), it’s up to you to make sure they don’t step on each other’s toes.
Note that accounts created after October 4, 2012 don’t have the Public folder enabled by default: Go here to enable it. If you get a message that the folder is deleted, just create a folder in the root named Public, and it should gain the special icon.
App folder access
Files will be stored in a subfolder under Apps (configurable in the app settings). Download URLs are generated on demand by calling the Dropbox API, and are only valid for 4 hours. This means your files are slightly less public, and you can isolate data from multiple sites by creating multiple apps.
In app folder mode, every call to #url on an attachment will result in an HTTP request to Dropbox. Whether or not this is acceptable will depend on what you’re storing and how you’re exposing it to users.
Ref. from here.
If you want to use dropbox pro version then use this steps for store generated url into database.
Then add this callback in model for store avatar_url in db.
after_commit :add_avatar_url_to_article, on: :create
private
def add_avatar_url_to_article
self.update_column(:avatar_url, self.avatar.url)
end
Let me know if you need any else.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With