O$5.1.1 Loading image file to a variable using HTTPRead.

Kelly Burgess kellyb at montana.com
Tue Jul 4 03:13:14 EDT 2017


Hi Mike,

>Has anyone an easier, more workable solution to retrieving an image from a website please?

Easier than what?

The code below pulls a jpg file into a picture field.  At the line 'Calculate iPicture as binField' you could do WriteBinFile(path,binField) instead.  Works in Studio 4.3.1 with http urls, works in Studio 5 and up with https urls.

But the url you cited isn't a normal JPG, it's some kind of photoshop format starting with FFD8 like a normal jpg, but then FFED which is I don't know what - so save to file will work, but showing it in an Omnis picture field may not.

Hope it helps,

Kelly

-----------

Calculate url as 'http://www.kellyb.com/RosettaOnLion.jpg'
HTTPPage (url) Returns binField
Calculate size as binlength(binField)
If size>0
  Calculate headerBreak as binfromhex('0D0A0D0A')
  Calculate pos as binsearch(headerBreak,binField)
  If pos>0
    Calculate binField as bytemid(binField,pos+4,size-1)
    Calculate iPicture as binField
    Do $cinst.$objs.dfPicture.$rawpictformat.$assign(pictformat(iPicture))
    Redraw {dfPicture}
  End If
End If




More information about the omnisdev-en mailing list