From b8b5c8d6a0b1eb5eec591615c0062a6e8c970b6d Mon Sep 17 00:00:00 2001 From: evazion Date: Wed, 17 Jun 2020 02:28:16 -0500 Subject: [PATCH] iqdb: fix error with file uploads. Fix "cannot determine size of body" errors on upload page. Caused by exception during IQDB lookup. We were posting the form data wrong, we need to wrap the file with HTTP::FormData::File and pass it through the `form` parameter. --- app/logical/iqdb_proxy.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/logical/iqdb_proxy.rb b/app/logical/iqdb_proxy.rb index e1b1f195f..a61dd3c2c 100644 --- a/app/logical/iqdb_proxy.rb +++ b/app/logical/iqdb_proxy.rb @@ -50,9 +50,12 @@ class IqdbProxy file.try(:close) end - def query(params) + def query(file: nil, url: nil, limit: 20) raise NotImplementedError, "the IQDBs service isn't configured" unless enabled? - response = http.post("#{iqdbs_server}/similar", body: params) + + file = HTTP::FormData::File.new(file) if file + form = { file: file, url: url, limit: limit }.compact + response = http.post("#{iqdbs_server}/similar", form: form) raise Error, "IQDB error: #{response.status}" if response.status != 200 raise Error, "IQDB error: #{response.parse["error"]}" if response.parse.is_a?(Hash)