Rails - read file from POST request / octet-stream

565 Views Asked by At

I'm sending a photo in a POST request with Content-Type: binary/octect-stream from an android application and I don't know how to read it in the server side. The current code is returning a 500 error:

  def send_photo_attachment
    @tempfile = Tempfile.new
    @tempfile.binmode
    @tempfile.write request.body.read
    @tempfile.rewind

    uploaded_file = ActionDispatch::Http::UploadedFile.new(
          tempfile: @tempfile,
          filename: "photo.jpg"
        )
    uploaded_file.content_type = "image/jpeg"
    @message_content = MessageContent.new
    @message_content.content = uploaded_file
    @message_content.mimetype = "image/jpeg"
    render :attachment_id
  end

Any help will be appreciated.

0

There are 0 best solutions below