upload raises exception in Sinatra app
Cloudinary using cloudinary gem v1.9.1, and configured by defining CLOUDINARY_URL environment variable
The file is uploaded with an Axios.post and it seems to arrive successfully in my Sinatra v2.0.0 app. The app sees the file as follows:
- {"filename"=>"advanced.jpg", "type"=>"image/jpeg", "name"=>"image", "tempfile"=>#<Tempfile:/var/folders/kf/gwsv0dmd6rl021zm7khjfj9r0000gp/T/RackMultipart20180308-67019-16b0l5i.jpg>, "head"=>"Content-Disposition: form-data; name=\"image\"; filename=\"advanced.jpg\"\r\nContent-Type: image/jpeg\r\n"}
but when Cloudinary::Uploader.upload() is run, I get this exception:
- undefined method `match' for #<Sinatra::IndifferentHash:0x007fad90bae268>Did you mean? catch
I don't really know what is causing that. Is the file representation wrong, or is there configuration that I'm missing, or....?
-
Ok, I figured it out. The hint's in the exception, even if it was a bit confusing at first. The upload() method wants a file object or a string file path, not a hash, indifferent or otherwise. So, using file['tempfile'], or file['tempfile'].path does the trick. I guess it's the difference between a regular form submit, and an ajax request like I'm using here.
Post is closed for comments.
Comments
2 comments