Binary Data to Image

Hi all,

Im reading XML file which has Content tag which has binary data(i
assume). I need to read that content and store it as image.

Content Data in XML looks like this:
WEcxA1HTcsbiHgufPW41U1Du0HAdIY/WvTSB1s9NGtgW4W4BMSHJnnjF/m4K+vKuF0d8Q29yLWNzlvmT9orboet9EYouFMX9QvG3sV0PO7/gtXF7BjQGhGoSzh+Pg8iWk705TkOSm/5LrKOsqx5JrCNh4eqHTyuWBhV6PGDV+AUack69Diqei+DJUn2ze+5otVoSs2mgpiV4Wmp9Djc0rYXrrqDpmcxjIfo61uK3JpvaFBConokCgR1JKNS6BgMIDg==

XML Tag is :
WEcxA1HTcsbiHgufPW41U1Du0HAdIY/WvTSB1s9NGtgW4W4BMSHJnnjF/m4K+vKuF0d8Q29yLWNzlvmT9orboet9EYouFMX9QvG3sV0PO7/gtXF7BjQGhGoSzh+Pg8iWk705TkOSm/5LrKOsqx5JrCNh4eqHTyuWBhV6PGDV+AUack69Diqei+DJUn2ze+5otVoSs2mgpiV4Wmp9Djc0rYXrrqDpmcxjIfo61uK3JpvaFBConokCgR1JKNS6BgMIDg==

Please find the attach sample xml data. Code written so far is as
follows,

require ‘base64’
@content =
‘WEcxAyEJQTXiHgufhAdVefCCvSH2njBUZ/dzBOsTuNj9guPeaJrJL80KjGWl8dglgJ56veLnyl/Fdu8I1tS7uAR65G82/WxygyR/lOE7bNLMCHS1p3Ah48iCzQBSJ1jnOl1HuL8hAR0aGhHIN8oW7IofdVX0YPSaQoanrUkz7iPt56TbZH5qiynHqLD9ZepkDGpSAUuInzLZG/2BixmyuqH2ctZnMqPAJR4vveB7mT7KVsJRIofMZqK6ptHWRAmk4w==’
@filename= ‘Sana.jpg’

File.open(@filename, ‘wb’) do|f|

f.write(Base64.decode64(@content))
end

Please help im new to Ruby

-----Messaggio originale-----
Da: Sagar V. [mailto:[email protected]]
Inviato: gioved 29 dicembre 2011 08:42
A: ruby-talk ML
Oggetto: Binary Data to Image


Caselle da 1GB, trasmetti allegati fino a 3GB e in piu’ IMAP, POP3 e
SMTP autenticato? GRATIS solo con Email.it http://www.email.it/f

Sponsor:
Capodanno a Riccione, Pacchetto Relax: Mezza Pensione + bagno turco +
solarium + massaggio. Wifi e parcheggio gratis. 2 giorni euro 199 a
persona
Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid979&d)-12

On Thu, Dec 29, 2011 at 8:41 AM, Sagar V. [email protected]
wrote:

TYPE=“cover”>WEcxA1HTcsbiHgufPW41U1Du0HAdIY/WvTSB1s9NGtgW4W4BMSHJnnjF/m4K+vKuF0d8Q29yLWNzlvmT9orboet9EYouFMX9QvG3sV0PO7/gtXF7BjQGhGoSzh+Pg8iWk705TkOSm/5LrKOsqx5JrCNh4eqHTyuWBhV6PGDV+AUack69Diqei+DJUn2ze+5otVoSs2mgpiV4Wmp9Djc0rYXrrqDpmcxjIfo61uK3JpvaFBConokCgR1JKNS6BgMIDg==

BinaryString.
f.write(Base64.decode64(@content))

Why do you decode twice? You have the binary data already in str.

end

Please help im new to Ruby

Attachments:
http://www.ruby-forum.com/attachment/6868/_album__album_cover_search73.log

And where exactly is the problem?

Kind regards

robert

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs