Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.59 KB | None | 0 0
  1.         if params[:image] && params[:image][:tempfile] && params[:image][:filename]
  2.             begin
  3.                 token = "Bearer blahblahblah"
  4.                 file = params[:image][:tempfile]
  5.                 response = HTTParty.post("https://nameless-forest-80107.herokuapp.com/api/images", body: { image: file },  :headers => { "Authorization" => token} )
  6.                 data = JSON.parse(response.body)
  7.  
  8.                 #make post
  9.                 current_user.profile_image_url = data["url"]
  10.                 current_user.save
  11.                 halt 200, {"message" => "Image updated"}.to_json
  12.             rescue => e
  13.                 puts e.message
  14.                 halt 422, {message: "Unable to create image"}.to_json
  15.             end
  16.         end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement