Closed iroshiva closed 4 years ago
Sorry for my late answer. I was in vacation.
I didn't know active storage. Could you give some code of what you have tried?
Pictures taken from some phones (iPhone, 1+, ...) are rotated 90° or -90° or 180° The main utilisation of mini_exiftool is to get the orientation of an image and modify it if necessary.
I use dropzone to download pictures. The pictures are first send to my AWS account, then from the request of each pictures uploaded, i get the active storage blob and then i attach it to my model.
What i want is get the active blob storage AND use mini_exiftool to read the orientation of the picture to be able to change it if the picture is wrong oriented BEFORE attch it to the model.
I tried to apply mini_exiftool directly after getting the active storage blob
` require 'mini_exiftool'
@user = User.find(params[:user_id])
blob = ActiveStorage::Blob.create!(upload_params)
movie = MiniExiftool.new(blob)
puts "#" * 60
puts movie.orientation
puts "#" * 60
@user.images.attach(blob.signed_id)`
But have this error : MiniExiftool::Error (Could not open filename_or_io.):
Then, i tried to store the blob to public file and then to read it, but no success...
`require 'mini_exiftool'
@user = User.find(params[:user_id])
blob = ActiveStorage::Blob.create!(upload_params)
id = @user.name.to_s
unless Dir.exists?(Rails.root.join("public", "#{id}"))
FileUtils.mkdir_p(Rails.root.join("public", "#{id}"))
end
time_footprint = Time.now.to_i.to_s(:number)
File.open(Rails.root.join('public', "#{id}", blob.filename.to_s), 'wb') do |file|
File.rename(file, "public/#{id}/" + time_footprint + blob.filename.to_s)
movie = MiniExiftool.new("/public/#{id}/" + time_footprint + blob.filename.to_s)
puts "#" * 60
puts movie.orientation
puts "#" * 60
end
@user.images.attach(blob.signed_id)`
I have the error : MiniExiftool::Error (File '../public/admin/1598352666bantersnaps-y4bE8ST_CTg-unsplash.jpg' does not exist.):
The questions are:
Thx ! ;)
Could you try
blob.open do |file|
movie = MiniExiftool.new(file)
# ...
end
I got the error message : NoMethodError (private method
open' called for #
As already mentioned don't I know active storage. I have no idea why ActiveStorage::Blob#open not work since the api doc has an example which uses this method.
In short: MiniExiftool.new needs a valid filename or an instance of IO as parameter. Certainly someone who knows active storage could help you out. Maybe you could ask on a Rails forum how to get a filename or an IO instance from an ActiveStorage::Blob instance.
Yep, gonna investigate ! ;)
To be sure, if i succeed accessing to the orientation of the picture, i can modify it with mini_exiftool ?
Yes, mini_exiftool can write tags. But writing is only supported for files not for IO instances. So you have to save the content of your ActiveStorage::Blob instance as file, work on this file with mini_exiftool, and update your ActiveStorage::Blob instance from that file.
So it would be more the second option that i tried.
I succeed to save the blob as a file, but didn't succeed to open it with mini_exiftool...
`@user = User.find(params[:user_id])
blob = ActiveStorage::Blob.create!(upload_params)
id = @user.name.to_s time_footprint = Time.now.to_i.to_s(:number)
File.open(Rails.root.join('public', "#{id}", blob.filename.to_s), 'wb') do |file| File.rename(file, "public/#{id}/" + time_footprint + blob.filename.to_s)
movie = MiniExiftool.new("/public/#{id}/" + time_footprint + blob.filename.to_s) puts "#" 60 puts movie.orientation puts "#" 60 end `
Get : MiniExiftool::Error (File '../public/admin/1598352666bantersnaps-y4bE8ST_CTg-unsplash.jpg' does not exist.):
Maybe, i mistake the path ??
Why do you rename the file? It should be possible to use blob.filename directly:
movie = MiniExiftool.new(blob.filename)
You need the file only temporarly.
I hope you have solved your problem and close this issue now. Feel free to reopen it when you need further help.
Hi !
Is it possible to user mini_exiftool with a blob active storage ?
I tried to download the blob and put it in public folder but didn't figure it out the path to put it in
MiniExiftool.new
.Tried open, but get an error message
NoMethodError (private method
open' called for MiniExiftool:Class):`Don't understand how it works !!
Thx