So, after searching and experimenting a lot, I reached the conclusion that it might probably be best to not explicitly set the meta data myself, but have Dragonfly do that. To do this, I decided to "re-upload" the file through Dragonfly, using the URL of the image uploaded with Javascript as source. Once the image is "re-uploaded", we can then remove the originally uploaded image. All this is done in a "post_process" method on my image class, which is executed asynchronously:
def post_process
attachment_uid_after_upload = attachment_uid
attachment_name_after_upload = self.attachment_name
# Initialise a real Dragonfly attachment by assigning from URL.
# This way all meta data is set and saved correctly.
self.attachment_url = File.join(s3_url, attachment_uid_after_upload)
# We've seen spaces in filenames get replacesd by a literal '%20' string,
# which causes problems when trying to access this file on S3.
# Create the thumbnail
self.thumb = attachment.thumb('100x100>')
if self.save!
# Clean up the initially uploaded image
Dragonfly.app.datastore.destroy(attachment_uid_after_upload)
end
end
Even though it works, it does not feel like *the* best solution, since we're doing one upload too many. So I am still hoping to hear from anyone with a better approach to this.
Anyone?
Thanks, Pascal
Op maandag 29 juni 2015 17:06:46 UTC+2 schreef Pascal Lindelauf: