How to encode media in base64 given URL in Ruby

后端 未结 6 1100
野性不改
野性不改 2020-12-04 15:08

I\'m trying to upload an image to PingFM. Their documentation says:

media – base64 encoded media data.

I can access this image via the URL.

6条回答
  •  独厮守ぢ
    2020-12-04 15:52

    In case it's useful to others, here's how to save a screenshot as base64 using Watir

    browser = Watir::Browser.new(:chrome, {:chromeOptions => {:args => ['--headless', '--window-size=1000x1000']}})
    browser.goto("http://www.yourimage.com")
    browser.screenshot.base64
    

    The beauty of this is you don't need to store the image itself

提交回复
热议问题