From: Robert Klemme Date: 2011-12-29T21:48:33+09:00 Subject: Re: Binary Data to Image On Thu, Dec 29, 2011 at 8:41 AM, Sagar Varule wrote: > 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. > > Data in XML looks like this: > WEcxA1HTcsbiHgufPW41U1Du0HAdIY/WvTSB1s9NGtgW4W4BMSHJnnjF/m4K+vKuF0d8Q29yLWNzlvmT9orboet9EYouFMX9QvG3sV0PO7/gtXF7BjQGhGoSzh+Pg8iWk705TkOSm/5LrKOsqx5JrCNh4eqHTyuWBhV6PGDV+AUack69Diqei+DJUn2ze+5otVoSs2mgpiV4Wmp9Djc0rYXrrqDpmcxjIfo61uK3JpvaFBConokCgR1JKNS6BgMIDg== > > XML Tag is : > TYPE="cover">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' > str = Base64.decode64(@content) > File.open(@filename, 'wb') do|f| >  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 -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/