Image Data URI Active record Rails - ruby-on-rails

I am running an API Request in the Rails Console to return the data of a movie poster.
I start by specifying what the movie is so,
#movies = Movie.find('Iron Man')
It then returns the one of the posters' urls
http://d3gtl9l2a4fn1j.cloudfront.net/t/p/w92/s2IG9qXfhJYxIttKyroYFBsHwzQ.jpg
I then run a code to return the above poster's data, this is what it gives
> #movie.posters.first.data
=> "\xFF\xD8\xFF\xE0\x00\x10JFIF\x00\x01\x01\x01\x00H\x00H\x00\x00\xFF\xDB\x00C\x00\x03\x02\x02\x03\x02\x02\x03\x03\x03\x03\x04\x03\x03\x04\x05\b\x05\x05\x04\x04\x05\n\a\a\x06\b\f\n\f\f\v\n\v\v\r\x0E\x12\x10\r\x0E\x11\x0E\v\v\x10\x16\x10\x11\x13\x14\x15\x15\x15\f\x0F\x17\x18\x16\x14\x18\x12\x14\x15\x14\xFF\xDB\x00C\x01\x03\x04\x04\x05\x04\x05\t\x05\x05\t\x14\r\v\r\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\x14\xFF\xC0\x00\x11\b\x00\x8A\x00\\\x03\x01\x11\x00\x02\x11\x01\x03\x11\x01\xFF\xC4\x00\x1D\x00\x00\x01\x04\x03\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\a\x04\x05\x06\b\x00\x03\t\x02\x01\xFF\xC4\x00<\x10\x00\x01\x03\x02\x05\x01\a\x02\x05\x01\x05\t\x00\x00\x00\x00\x01\x02\x03\x04\x05\x11\x00\x06\a\x12!1\b\x13\x14\"AQa2q\x15R\x81\x91\xA1\t\x16#b\xC1\xD1\x17$34Br\x82\xA2\xB1\xFF\xC4\x00\x1C\x01\x00\x01\x05\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x05\x00\x02\x03\x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x1F1T\xE9\x94Z\xBAvT)\xF1%-\xB6%\xA6\xD6\xB3\xA8\x06\xCB\x16\xE3\x9C5\xF4\xF0\xC8\xF6\xC8\xF6\x02\xE6\xF0H\x04\x8FC\xD18=\xC0X\x1C,\xCDZ\x91\x9A\xB3\xCC*\\<\xC3\x98ju\xB8\xB4\xB6\xBB\x88,\xCF\x94\xB7\x93\x15\xBD\xA9N\xD6\xC2\x89\xDA,\x84\x8B\x0FD\x8Flr\x1Ah)\xCB\x9D\v\x03K\xB9\xB0\x02\xFE\xB6\xE5p\xBD\xCE\x00\x13{'\xCA\x8Fh\rJ\xAB\xC2\x93\x0Ev{\xCC\x12\xE2\xC9c\xC3>\xCB\xD5\x17T\x87\x1A\xB1\e\x14\t\xE56R\xB8\xF98\xAE4\xEA6\xB88B\xD0A\xBF\xE9\x1C\xF8\xFA\xF9\xA9\xBD\xE2n7\x9E-\xC9\xE3\xC3\xD13\xE5\x8DO\xCD\xD9*\x9B*\x9F#\xCC\xB5J4)N%\xD7\xA3\xC1\x96\xB6\x90\xE2\xC5\xAC\xA2\x12y\"\xC3\x9F\x8CO5,\x15\x0Ek\xA6`qo\x17\x00\xDB\xD1F\xC9\x1E\xC0C\x1CE\xD3~j\xCE\x15\xBC\xF1W]S0U\xA6V\xAAKBP\xA9s\x9ES\xAE\x14\xA4Y \xA9\\\xD8a\xD0S\xC3L\xCE\xCE\x06\x06\xB7\xC0\v\x05\xC7\xBD\xF2\x1D\xCF7>i\xA3\x16\x13\x17\xA3\x8E\x94\x97\x9Cq%\x98I,\xC2If\x12K0\x92Y\x84\x92\xCC$\x96a$\xB3\t%\x98I,\xC2I\x7F\xFF\xD9"
So the above data should display the above poster.
But when i add that code
<img src="data:image/gif;base64,**HERE**" />
The movie poster isnt shown, does anyone have any idea why?

I can see one possible error. The image link you have posted in .jpg while you are setting mime-type as gif. Please check with mime type as image/jpeg.
EDIT:
I tried the following sample code, works fine:
<%
require 'open-uri'
raw_img_data= nil
open('http://d3gtl9l2a4fn1j.cloudfront.net/t/p/w92/s2IG9qXfhJYxIttKyroYFBsHwzQ.jpg') do |f| raw_img_data= f.read end
base_64_img_data= Base64.encode64(raw_img_data)
%>
<img src="data:image/jpeg;base64,<%= base_64_img_data%>" />
Did you encode the raw image data to base64 before placing it as part of the URI?

Related

Rails: Received string from web service should be converted to a pdf image to be displayed

When using a web service I receive a string that looks like this:
JVBERi0xLjIgDQoxIDAgb2JqDQo8PA0KL1R5cGUgL0NhdGFsb2cNCi9QYWdlcyAzIDAgUg0KL1BhZ2VNb2RlIC9Vc2VOb25lDQovUGFnZUxheW91dCAvU2luZ2xlUGFnZQ0KPj4NCmVuZG9iag0KMiAwIG9iag0KPDwNCi9Qcm9kdWNlciAoUGRmQ3JlYXRvciB2ZXJzaW9uIDEuMCkNCi9BdXRob3IgKCkNCi9DcmVhdGlvbkRhdGUgKEQ6MjAxNzA4MjUxMTM0MDApDQovQ3JlYXRvciAoKQ0KL0tleXdvcmRzICgpDQovU3ViamVjdCAoKQ0KL1RpdGxlICgpDQovTW9kRGF0ZSAoRDoyMDE3MDgyNTExMzQwMCkNCj4+DQplbmRvYmoNCjMgMCBvYmoNCjw8DQovVHlwZSAvUGFnZXMNCi9LaWRzIFs0IDAgUiBdDQovQ291bnQgMQ0KPj4NCmVuZG9iag0KNCAwIG9iag0KPDwNCi9UeXBlIC9QYWdlDQovUGFyZW50IDMgMCBSDQovTWVkaWFCb3ggWzAgMCA0MjUgMjkyIF0NCi9SZXNvdXJjZXMgPDwNCi9Gb250IDw8DQovRjAgNiAwIFINCi9GMSA4IDAgUg0KPj4NCi9YT2JqZWN0IDw8DQovMCA3IDAgUg0KPj4NCi9Qcm9jU2V0IFsvUERGIC9UZXh0IC9JbWFnZUMgXQ0KPj4NCi9Db250ZW50cyA1IDAgUg0KPj4NCmVuZG9iag0KNSAwIG9iag0KPDwNCi9MZW5ndGggNDE4DQovRmlsdGVyIFsvRmxhdGVEZWNvZGUgXQ0KPj4NCnN0cmVhbQ0Ke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mVuZG9iag0KeHJlZg0KMCA5DQowMDAwMDAwMDAwIDY1NTM1IGYNCjAwMDAwMDAwMTEgMDAwMDAgbg0KMDAwMDAwMDExMSAwMDAwMCBuDQowMDAwMDAwMjk4IDAwMDAwIG4NCjAwMDAwMDAzNjMgMDAwMDAgbg0KMDAwMDAwMDU3MyAwMDAwMCBuDQowMDAwMDAxMDc0IDAwMDAwIG4NCjAwMDAwMDMwMDcgMDAwMDAgbg0KMDAwMDAwNDk1MSAwMDAwMCBuDQp0cmFpbGVyDQo8PA0KL1NpemUgOQ0KL1Jvb3QgMSAwIFINCi9JbmZvIDIgMCBSDQo+Pg0Kc3RhcnR4cmVmDQo2ODg4DQolJUVPRg0K
Sorry for that.
Anyway, this should be a pdf because that was one of the request parameters. (I could also have chosen for .gif, or .jpg in different qualities.)
I tried reading the content, like this:
#label_binary = #response_label[:generate_label_response][:response_shipments][:response_shipment][:labels][:label][:content]
binary_data = Base64.decode64(#label_binary)
#label = File.open('file_name.pdf', 'wb') {|f| f.write(Base64.decode64(binary_data))}
But what this prints then as #label is just a number (three of four digits). Same when I use urlsafe_decode64.
Not very helpful.
Preferred end-result would be a pdf image file that I can immediately display (in this case a barcode on top of an invoice for sending a package).
Could I for this purpose save the file temporarily? Meaning: every time I need to display I rebuild this image. I think that would be best.
EDIT
I am making the call now directly to a 600dpi .jpg image and then:
base_64_binary_data = #response_label[:generate_label_response][:response_shipments][:response_shipment][:labels][:label][:content]
#jpg_file = File.open('label.jpg', 'wb') do |file|
content = Base64.decode64 base_64_binary_data
file << content
end
This file shows up at my_apps_name/label.jpg.
In my filesystem I can see the picture crystal clear.
In my view I then put:
<%= image_tag #jpg_file.path %>
When I inspect my html in the browser I see:
<img src="/images/label.jpg" alt="Label">
I suppose this is easily fixed, suggestions are still welcome of course, but...
..more importantly: What if this call is made several times at once. Will rails manage? Should I maybe save these images (to my S3) or build some kind of chronejob to manage it?
(I am not sure of the added value of mini_magic anymore, since I can see the .jpg being already there.)
Then on a complete side note, maybe better left for a separate question: what if the API on the other side fails?
Step one
decode http response
require "base64"
BASE_64_BINARY_DATA = "PASTE YOUR BIG STRING HERE"
pdf_file = File.open('your_pdf.pdf', 'wb') do |file|
content = Base64.decode64 BASE_64_BINARY_DATA
file << content
end
Step two
convert pdf file to an image
add to gemfile 'gem 'mini_magick' and use 'bundle install' command
put somewhere in your code
require 'mini_magick'
pdf = MiniMagick::Image.new(pdf_file.path)
pdf.pages.first.write("preview.png")
image saved as preview.png
To display pdf image put in the view
<%= image_tag ("path_to_image/preview.jpg")%>

Rails Upload a File

I'm using rails 3.2.13, and i need to upload a file manually (not using paperclip) and then convert it base 64.
The problem i have is that i think my file is not uploaded completly.
I am trying to upload a jpg.
Here is the code : the form
= form_tag send_kyc_docs_bookings_path , :multipart => true do
= file_field_tag :kyc_doc
= submit_tag "Submit"
My controller
#encoded_file = Base64.encode64(File.open(params[:kyc_doc].tempfile,"r").read)
What i get is
"/9j/4AAQSkZJRgABAQEAtAC0AAD/4R5kRXhpZgAASUkqAAgAAAAQAA8BAgAG\nAAAAzgAAABABAgAVAAAA1AAAABIBAwABAAAAAQAAAA==\n"
Now if i go on http://www.base64-image.de/step-2.php
I upload my file and get a string beginning like mine above but 1000 times longer.
So i came to the point that my file was not uploaded completly and here is my question:
how can i upload it completly?
Just for you to underqtand if i do
File.open(params[:kyc_doc].tempfile,"r").read
i get
"\xFF\xD8\xFF\xE0\u0000\u0010JFIF\u0000\u0001\u0001\u0001\u0000\xB4\u0000\xB4\u0000\u0000\xFF\xE1\u001EdExif\u0000\u0000II*\u0000\b\u0000\u0000\u0000\u0010\u0000\u000F\u0001\u0002\u0000\u0006\u0000\u0000\u0000\xCE\u0000\u0000\u0000\u0010\u0001\u0002\u0000\u0015\u0000\u0000\u0000\xD4\u0000\u0000\u0000\u0012\u0001\u0003\u0000\u0001\u0000\u0000\u0000\u0001\u0000\u0000\u0000"
Now if i do
params[:kyc_doc].tempfile.read
i get
"\xFF\xD8\xFF\xE0\x00\x10JFIF\x00\x01\x01\x01\x00\xB4\x00\xB4\x00\x00\xFF\xE1\x1EdExif\x00\x00II*\x00\b\x00\x00\x00\x10\x00\x0F\x01\x02\x00\x06\x00\x00\x00\xCE\x00\x00\x00\x10\x01\x02\x00\x15\x00\x00\x00\xD4\x00\x00\x00\x12\x01\x03\x00\x01\x00\x00\x00\x01\x00\x00\x00\x1A\x01\x05\x00\x01\x00\x00\x00\xEA\x00\x00\x00\e\x01\x05\x00\x01\x00\x00\x00\xF2\x00\x00\x00(\x01\x03\x00\x01\x00\x00\x00\x02\x00\x00\x002\x01\x02\x00\x14\x00\x00\x00\xFA\x00\x00\x00\x13\x02\x03\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01\x10\x03\x00\x01\x00\x00\x00\x00\b\x00\x00\x02\x10\x03\x00\x01\x00\x00\x00\x00\x06\x00\x00i\x87\x04\x00\x01\x00\x00\x00\x16\x01\x00\x00\x01\xA4\x03\x00\x01\x00\x00\x00\x00\x00\x00\x00\x02\xA4\x03\x00\x01\x00\x00\x00\x00\x00\x00\x00\x03\xA4\x03\x00\x01\x00\x00\x00\x00\x00\x00\x00\x04\xA4\x05\x00\x01\x00\x00\x00\x0E\x01\x00\x00\x06\xA4\x03\x00\x01\x00\x00\x00\x00\x00\x00\x00\xBC\x03\x00\x00Canon\x00Canon PowerShot A610\x00\x00\xB4\x00\x00\x00\x01\x00\x00\x00\xB4\x00\x00\x00\x01\x00\x00\x002009:03:18 16:30:39\x00 \n\x00\x00 .... (1000 times longer)
however doing
Base64.encode64(params[:kyc_doc].tempfile.read)
return an empty string
Update :
File.open(params[:kyc_doc].tempfile,"r").size
=> 241202
>> File.open(params[:kyc_doc].tempfile,"r").read.size
=> 76
has anyone an idea on the subject?
Thanks
ANSWER
Ok so i figured it out, in fact when you do
File.open(params[:kyc_doc].tempfile,"r")
It only see the first caracteres of the file (maybe because of the buffer size?)
so you need to iterate through the all sets of caracteres containing in the doc by doing
File.open(params[:kyc_doc].tempfile, "rb") {|io| io.read}
this will output all the document content
and now you can properly encode it
#encoded_file =
Base64.encode64(File.open(params[:kyc_doc].tempfile,"rb") {|io|
io.read})
If anyone can explain it better, i would be glad to hear it ^^

Image source path in application_helper.rb in Rails

In my Rails app, I am using a img tag in Application_helper.rb, But I think Assests pipeline is not working here, So the image is not loading on the page. And Browser console show as error of "failed to load the given URL".
One line fro my code block is as :
text = "<input type='checkbox'/><img src='Icon_Bar.png' />#{r[:value]}<span class='small'>(#{r[:count]})</span>".html_safe
And it works fine, when I used any online path for the image. Please Help.
Try this,
text = "<input type='checkbox'/><img src='/assets/Icon_Bar.png' />#{r[:value]}<span class='small'>(#{r[:count]})</span>".html_safe
Add /assets/ before the image.extension.
when Icon_Bar.png in assets/images/Icon_Bar.png
Try:
<img src="<%= image_path('Icon_Bar.png') %>" />
The doc is here: http://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html#method-i-image_path
Try :
<%= image_tag("Icon_Bar.png") %>
Watch out for the capital letters , they also matter in referencing to assets.

How will I save data from javascript's canvas.toDataURL to an image file in ruby?

How will I save data from javascript's canvas.toDataURL to an image file in ruby?
The sample code below create the image but gives an error saying the format is not recognized or damaged
require 'base64'
chart1 = params[:chart1].split(',')
image = Base64.decode64(chart1[1])
File.open("#{Rails.root}/test.png", 'wb') do|f|
f.write(image)
end
Thanks!
NOTE: Edited. This is now ok and working
Copying the answer from the comments in order to remove this question from the "Unanswered" filter:
p0rter noticed:
why do you have to call Base64.decode64 twice?
steamboy acknowledged:
#p0rter nice catch. its now working. tnx

How to check if a url contains video?

hi
i am creating a script ruby on rails in which user shares a link and if the link contains a video, the embed code of the video is extracted. in other words, i am trying to implement a "facebook post link" like feature.. can someone please guide me how can this be achieved??
The only way I can think of to do this would be to manually check each post for a link to the video, for example:
YOUTUBE_EMBED = '<iframe title="YouTube video player" width="640" height="390" src="http://www.youtube.com/embed/VIDEO_ID" frameborder="0" allowfullscreen></iframe>'
if comment =~ /.*http:\/\/(\w+\.)?youtube.com\/watch\?v=(\w+).*/
return YOUTUBE_EMBED.gsub(/VIDEO_ID/, $2)
end
Then repeat this process for each video site. I am wrestling with a similar concept so if you figure out a better way to do it let me know!
You can analyze http headers for that link
require "net/http"
Net::HTTP.start('www.jhepple.com', 80) do |http|
http.head('/support/SampleMovies/MPEG-1.mpg')
end['content-type']
Outputs "video/mpeg"
Now that you know it's really a video, do what you want with it
You could also use a utility like file and fork a system process so that it executes a command like file -b downloaded_file.mpg.
So your code would look something like this:
IO.popen("file -b /path/to/video.mpg") { |stdout| #stdout = stdout.gets }
if not #stdout.grep(/MPEG/).empty?
puts "MPEG Detected"
end
Flash videos usually have the extension .flv, so you just need to look for files that have it.
html_souce.scan(%r|href\s*=\s*\"[^\"]+\.flv\"|)
If you need other file formats, just change the regexp.
You can use an external service like embedl.ly
Here you're a gem that may help you https://github.com/judofyr/ruby-oembed

Resources