Sha256: 7bb6819ee771ce41cb9fcea55c4259cbbf23dcbe60396bf762a4b66a90e0ce7e
Contents?: true
Size: 841 Bytes
Versions: 67
Compression:
Stored size: 841 Bytes
Contents
module FileHelper def file_params(file_path) { size: File.open(file_path).size, name: File.basename(file_path) } end def declare_file(api_path, params) post(api_path, params) end def post_file(url, params, file_path) params['Filename'] = File.basename(file_path) params['file'] = Faraday::UploadIO.new(file_path, params['content-type']) response = upload_connection.post(url, params) if [302, 303].include? response.status #success if it is a redirect response.headers['Location'] else raise 'FailedFileUpload' end end def confirm_file_upload(url) uri = URI(url) post(uri.path, CGI::parse(uri.query)) end def upload_connection Faraday.new do |f| f.request :multipart f.request :url_encoded f.adapter :net_http end end end
Version data entries
67 entries across 67 versions & 1 rubygems