lib/bunny_cdn/storage.rb in bunny_cdn-1.1.1 vs lib/bunny_cdn/storage.rb in bunny_cdn-1.2.0

- old
+ new

@@ -57,11 +57,11 @@ return exception end return response.body end - # Uploads a file to the storage zone + # Uploads a file on the system to the storage zone # Params: # +path+:: desired path to upload file # +file+:: specific file to upload to storage zone def self.uploadFile(path= '', file) fileName = File.basename(file) @@ -69,9 +69,27 @@ :accessKey => apiKey, :checksum => '' } begin response = RestClient.put("#{set_region_url}/#{storageZone}/#{path}/#{fileName}", File.read(file), headers) + rescue RestClient::ExceptionWithResponse => exception + return exception + end + return response.body + end + + # Uploads a file from a file input to the storage zone + # Params: + # +path+:: desired path to upload file + # +file+:: specific file to upload to storage zone + def self.uploadFormFile(path= '', file) + fileName = file.original_filename + headers = { + :accessKey => apiKey, + :checksum => '' + } + begin + response = RestClient.put("#{set_region_url}/#{storageZone}/#{path}/#{fileName}", File.read(file.tempfile), headers) rescue RestClient::ExceptionWithResponse => exception return exception end return response.body end \ No newline at end of file