Created
July 29, 2011 02:51
-
-
Save earlonrails/1113038 to your computer and use it in GitHub Desktop.
send a jpeg file over https using ruby. Also including rails controller receiving method.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def receive_images_contr_method | |
image_path = "tmp/my_img#{params[:id_my_img]}.jpg" | |
content_length = request.content_length | |
my_read = request.body.read(content_length) | |
my_base64 = Base64.decode64(my_read) | |
image = open(image_path, "w") | |
image.write(my_base64) | |
image.close | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'uri' | |
require 'base64' | |
require 'net/http' | |
require 'net/https' | |
img_file = "my_img.jpg" | |
img_url = "www.my_url.com/img/receive_images_contr_method?id_my_img=1" | |
url = URI.parse(img_url) | |
file = open(img_file) | |
http = Net::HTTP.new(url.host, url.port) | |
http.use_ssl = (url.scheme == 'https') | |
http.verify_mode = OpenSSL::SSL::VERIFY_NONE | |
request = Net::HTTP::Post.new(url.path + '?' + url.query) | |
request.body = Base64.encode64(file.read) | |
request["Content-Type"] = "text/plain" | |
response = http.request(request) | |
response.code | |
response.body | |
file.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
small improvement