19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/imager/server_interface.rb', line 19
def self.post(collection, album, file, sizes, file_id = nil)
raise Imager::ImagerError "File is empty", caller unless file
if file.is_a?(String)
raise Imager::ImagerError, "File is not a file", caller unless File.file?(file)
file = File.new(file)
end
options = {}
options[:collection] = collection.to_s
options[:album] = album.to_s
options[:sizes] = sizes
options[:file_id] = file_id
options[:file_id] ||= file.original_filename if file.respond_to?(:original_filename)
options[:file_id] ||= File.basename(file)
options[:file_id].gsub!(/(\..{3,4})\z/i, '')
begin
options[:file_md5] = Digest::MD5.file(file)
options[:file_sha1] = Digest::SHA1.file(file)
rescue
raise Imager::ImagerError, "Cannot read the file", caller unless file.respond_to?(:read)
options[:file_md5] = Digest::MD5.hexdigest(file.read)
options[:file_sha1] = Digest::SHA1.hexdigest(file.read)
end
options_json = JSON.generate(options);
query = {
file: file,
options: options_json,
auth: auth_token(options_json)
};
return parse client.post('/post.php', multipart: true, body: query)
end
|