Method: SBF::Client::PhotoEndpoint#upload

Defined in:
lib/stbaldricks/endpoints/photo.rb

#upload(image_data_url, data = {}, with = {}) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/stbaldricks/endpoints/photo.rb', line 49

def upload(image_data_url, data = {}, with = {})
  # support image formats: png, jpeg, gif
  image_data_url.slice!(/data:image\/(png|jpeg|gif);base64,/)
  image_data = Base64.decode64(image_data_url)

  Tempfile.create('photo_upload') do |file|
    file.binmode
    file.write(image_data)
    file.seek(0)

    photo = photo_for_upload(file, data)
    photo.id.nil? ? create(photo, with) : update(photo.id, photo, with)
  end
end