SEE UPDATE BELOW!
I am having problems after I upload an image file to Amazon S3 and then try to save the file.
I use direct_fog_url(with_path: true) to get the the url of the image uploaded. I then get the following error:
ActiveRecord::RecordInvalid Validation failed: Image could not download file
I saw these two possible solutions:
https://github.com/jnicklas/carrierwave/issues/700
http://www.github.com/jnicklas/carrierwave/issues/888
But neither one seems to work.
Im using the older deleted command: overwriting method process_uri (enter link description here):
def process_uri(uri)
URI.parse(URI.escape(URI.unescape(uri)).gsub("[", "%5B").gsub("]", "%5D").gsub("+", "%2B"))
end
In my application I am using the following Gems:
gem 'fog'
gem 'carrierwave'
gem 'carrierwave_direct'
gem 'rmagick'
Thanks!
UPDATE: After implementing #Alex's answer below we resolved that problem but now when we do the upload we get the following error:
Excon::Errors::MovedPermanently
PermanentRedirect
The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.
For your Excon::Errors::MovedPermanently issue, make sure that you have the right data center region configured in your carrierwave.rb file. For example, if you're hosted on us-west, your region needs to be set to us-west.
Have you found a solution to this problem yet?
I'm facing the same problem here, I'm trying to fetch a remote URL with carrierwave (not on S3) and I get the notorious 'could not download file' error:
Validation failed: Image could not download file
[...]/gems/activerecord-3.2.9/lib/active_record/validations.rb:56:in `save!'
Could you post your URL to see what special characters there are?
EDIT: I found a solution. My case required that I did not change or escape the uri at all. I found that by adding 'return' to the 'def process_uri(uri)' method it works just fine.
Just in case this is useful to someone else, this is my overriding method in my uploader class:
def process_uri(uri)
return URI.parse(uri)
end
Related
I'm building an API with Grape on Rails 4.2. Here's a link to the repo on GitHub.
On the frontend, I have a JavaScript application built with EmberJS. Here's the link to the repo on GitHub as well.
I have updated the following gems so that I can format the responses of my API following JSON API standard, which appears to be required to update to Ember 1.13, then to Ember 2.0.
gem "active_model_serializers", '0.10.0.rc2'
gem "grape"
gem "grape-active_model_serializers", :git => 'https://github.com/jrhe/grape-active_model_serializers.git'
After that, I've got the following error when I call the API: IOError: Not opened for reading
According to the information I gathered here and there, I suspect this is a conflict with how I format JSON.
In default.rb, the file that inherit all API controllers, when I comment this line:
formatter :json, Grape::Formatter::ActiveModelSerializers
I don't have any error anymore, but obviously the response isn't serialized.
My questions are:
Do you have any idea how I can solve this?
Do you think it's relevant to use Grape to build the API in my Rails app? With Rails 5 coming, isn't that better to user rails-api and rewrite the whole app? I mean, I'm starting, it's maybe the right time to do that...
Let me know if you need more information.
Thanks in advance for your help.
I ended up rewriting the whole API using jsonapi-resources.
I have a rails app in which a user can upload images that will then be altered into the background and emailed to them. I am using carrierwave and in my perform_asycn method, I am passing in the tempfile/path to my sidekiq worker, however, I get an error saying that the file doesn't exsist.
controller
ImageWorker.perform_asycn(params["image"].tempfile.path)
class ImageWorker
def perform(path)
avatar = ImageList.new(path).last
#do other stuff
end
I get an ImageMagick error saying unable to open image: No such file or directory. Just to test, I tried to use Rmagick in the controller before I pass the path argument to the worker and everything works fine. I'm guessing carrierwave gets rid of the file once its passes it out of the controller but I don't know how I can access the file I want in the sidekiq worker.
This is appears because your temporary file was removed after complete request. So, in you worker you a trying to open file which has been removed.
So, in you case I recommend to use carrierwave_backgrounder. It should handle this case correctly.
I'm using PDFKit to create pdfs of from a given url within a Resque job on Heroku Cedar. My code looks like:
kit = PDFKit.new(url)
pdf = kit.to_file("/tmp/#{SecureRandom.hex}.pdf")
I then upload the file using fog to S3 for permanent storage. This job usually works, but also fails maybe a third of the time with:
No such file or directory - /tmp/a05c165fc80878b75fd15c447695de71.pdf
Manually running through the code in console will produce the same error.
According to the Heroku docs, I should be able to write a temporary file anywhere in the app's directory on Cedar. I've tried creating the tmp directory first (in console) but that didn't seem to change anything. Neither did saving to "#{Rails.root}/tmp/#{SecureRandom.hex}.pdf".
Any ideas would be greatly appreciated.
UPDATE
The full error in console is:
Error: Failed loading page http://grist.org/living/you-look-great-in-green-clothing-industry-gets-a-makeover-maybe.html
(sometimes it will work just to ignore this error with --load-error-handling ignore)
Errno::ENOENT: No such file or directory - /tmp/55a1d418074736decfd4e123d8e2bba2.pdf
It seems that maybe this is an error coming from wkhtmltopdf, however, I'm not sure where to add this flag if I'm using wkhtmltopdf via PDFkit.
Looks like the solution, as the error I posted second suggested, was to ignore the load error. I did this with:
PDFKit.configure do |config|
config.default_options[:load_error_handling] = 'ignore'
end
I wasn't seeing this warning at first because Resque was only showing me the final error. Thanks #ctshryock, your question made me think a little more about exactly where this error was coming from.
my rails app is configured to use the app_folder access but when I try to upload a file in development, Rails throws me this error:
Host: rpc.dropbox.com:443, FE: None, X-Dropbox-RequestId: None, X-Dropbox-App-Error: None, Full Dropbox access attempt failed because this app is not configured to have full Dropbox access. Should your access type be app folder ('sandbox') instead?
At first I thought maybe I entered the value wrong. My variable looks like this:
DROPBOX_ACCESS_TYPE: app_folder
Any ideas?
Janko, the creator of the gem solved it by telling me to update the gem
I found an Amazon Gem that I want to use https://github.com/hakanensari/vacuum/.
I've only ever used gems with in depth tutorials or following a RailsCast. I'm looking for tips on using gems I find online. I'll explain the steps I'm doing, and hopefully someone can give me some ideas on what else I should be doing when using a new gem. Also, if you have a good tutorial or explanation on gems, that would be great too.
I started off examining the Gem on Github, I'll point out the things I took notice of. Let me know if there are things I'm missing I should notice.
Examining Gem on Github
Go to the examples and look at "examples/product_advertising/basic_lookup.rb"
Follow the required file, and checkout "examples/product_advertising/shared.rb"
Notice, I need to install "pry"
Notice, the examples expand on the "lib" folder
Check out "credentials.yml"
Notice a "#req" is instantiated as a new Vacuum object.
Then back in basic_lookup.rb, it looks like it's assigning the lookup value, then binding the response to some kind of "pry" view.
Next, I'll try implementing these examples in my own project. Here's where I'm not sure what to do as far, as files are concerned.
Attempt Implementing Example
Install vacuum gem
gem install vacuum
Install pry gem
gem install pry
Added "shared.rb" and "credentials.yml" to my "app/controllers" directory
Replaced the information in "credentials.yml" with my information
Attempt to copy the information from "basic_lookup.rb" into an existing controller
def amazon
require File.expand_path('../shared.rb', __FILE__)
res = #req.look_up '0816614024'
items = res.find 'Item'
binding.pry
end
Create a route
match '/test' => 'products#amazon'
Go to test page and receive the following error
undefined method 'look_up' for nil:NilClass
I would like to point out, at this point I haven't added the lib folder.
Questions
I like the credentials.yml is separated out, when I want to add this to my project, where should I save that file?
I like the shared.rb file, should I just put that in the controller folder?
Why is it referencing the "lib" folder in "shared.rb"? Do I need to copy that directory into my project?
I appreciate you sticking around and reading all of this. I'm still trying to get a handle on using a gems, so any help or tips are great. Really, I'm just trying to figure out, how do I find any gem and start using it appropriately.
Thanks for any help you can give me!
I like the shared.rb file, should I just put that in the controller folder?
Answer = yes, you just put that file in controller folder.