app/controllers/api/snaps_controller.rb
def storeSearchedResult
    # Get parameters from the request
    query_image_path = params[:image].tempfile.path()
    reference_image_url = if params[:referenceImageUrl] === 'null' then nil else params[:referenceImageUrl] end

    # Get the data data uri
    query_image_uri = 'data:image/jpeg;base64,' + Base64.encode64(open(query_image_path) { |io| io.read })

    if params[:scanSeqId].present?
      @album = Album.find_or_create_by(unique_identifier: params[:scanSeqId], session_id: @session.id)

      @photo = @album.photos.create(
        searched_image_blob: query_image_uri,
        es_response: params[:esResponse] == 'null' ? nil : params[:esResponse],
        response_time: params[:searchTime],
        result_image_url: reference_image_url,
        search_engine: 'Catchoom API'
      )

      if @photo
        ImageUploadJob.perform_later(@album.id, @photo.id)
      end
    end

    if File.exists?(query_image_path)
      File.delete(query_image_path)
    end

    render json: 'Image was stored'
  end
## Stores the provided image result in the Snap dashboard
Stores the provided image result in the Snap dashboard
Stores the provided image result in the Snap dashboard
def storeSearchedResult
    query_image_path = params[:image].tempfile.path()
    reference_image_url = if params[:referenceImageUrl] === 'null' then nil else params[:referenceImageUrl] end
    query_image_uri = 'data:image/jpeg;base64,' + Base64.encode64(open(query_image_path) { |io| io.read })
    if params[:scanSeqId].present?
      @album = Album.find_or_create_by(unique_identifier: params[:scanSeqId], session_id: @session.id)
      @photo = @album.photos.create(
        searched_image_blob: query_image_uri,
        es_response: params[:esResponse] == 'null' ? nil : params[:esResponse],
        response_time: params[:searchTime],
        result_image_url: reference_image_url,
        search_engine: 'Catchoom API'
      )
      if @photo
        ImageUploadJob.perform_later(@album.id, @photo.id)
      end
    end
    if File.exists?(query_image_path)
      File.delete(query_image_path)
    end
    render json: 'Image was stored'
  end
def storeSearchedResult query_image_path = params [ :image ] . tempfile . path ( ) reference_image_url = if params [ :referenceImageUrl ] === 'null' then nil else params [ :referenceImageUrl ] end query_image_uri = 'data:image/jpeg;base64,' + Base64 . encode64 ( open ( query_image_path ) { | io | io . read } ) if params [ :scanSeqId ] . present? @album = Album . find_or_create_by ( unique_identifier : params [ :scanSeqId ] , session_id : @session . id ) @photo = @album . photos . create ( searched_image_blob : query_image_uri , es_response : params [ :esResponse ] == 'null' ? nil : params [ :esResponse ] , response_time : params [ :searchTime ] , result_image_url : reference_image_url , search_engine : 'Catchoom API' ) if @photo ImageUploadJob . perform_later ( @album . id , @photo . id ) end end if File . exists? ( query_image_path ) File . delete ( query_image_path ) end render json : 'Image was stored' end
Stores the provided image result in the Snap dashboard
Stores the provided image result in the Snap dashboard
# Get parameters from the request # Get the data data uri