Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Would prefer that attachment content are not uploaded to Cloudinary until the model otherwise passes validations #129

Open
rdnewman opened this issue May 13, 2016 · 1 comment

Comments

@rdnewman
Copy link

For instance, given the following model:

class SomeModel < ActiveRecord::Base
  has_attachment :image, accept: [:png]
  validates :name, presence: true     # where name is an unrelated field to the image attachment
end

and a statement

sm = SomeModel.new(image: File.open('/path/to/file.png'));

my tests indicate that the image given will be uploaded to Cloudinary even though the model itself can't be created due to a failed validation. This appears to be true because upload happens during the initialize assignment of values to model attributes.

I was able to work around it in my model to defer the upload until after_create, but I'd prefer not to. The other alternative I suppose is to rollback the upload (i.e., remove from Cloudinary) on a failed create.

@nicowenterodt
Copy link

nicowenterodt commented Aug 12, 2016

yes. that's true. I recognized the same behaviour. This leeds to massive unused resources on the cloudinary side exceeding the storage capacity quickly

However it would be ok when the tmp-tag would be added, so we could clean unused images as described here: https://github.com/assembler/attachinary/wiki/How-to-cleanup-unused-uploads

But that doesn't work.

When I build a new Object like
Post.new(media_url: "http://example.com/your-image.jpg")

The file is uploaded directly: ok so far. But as I not saved the entity locally I assume the Attachinary::TMPTAG is added to the cloudinary-resource. But it is not. When I fetch the tagged resources I get an empty array:
Cloudinary::Api.resources_by_tag(Attachinary::TMPTAG)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants