Skip to content

Instantly share code, notes, and snippets.

@aponcz
Created June 19, 2018 16:47
Show Gist options
  • Save aponcz/7d9f796285a9b2920652b4d6297f2001 to your computer and use it in GitHub Desktop.
Save aponcz/7d9f796285a9b2920652b4d6297f2001 to your computer and use it in GitHub Desktop.
uuid = SecureRandom.uuid
newline = "\r\n"
boundary = "----------#{Time.now.nsec}"
folder_id = 654664
file_path = Rails.root.join("sample.pdf")
file = File.read(file_path)
uri_str = "https://www4.idealsvdr.com/v3/api/File/UploadFile?contentLength=#{file.size}&fileName=#{file_path.basename.to_s}&folderId=#{folder_id}&resumeSize=0&uid=#{uuid}"
uri = URI.parse(uri_str)
post_body = []
post_body << "--#{boundary}#{newline}"
post_body << "Content-Disposition: form-data; name=\"_chunkSize\"#{newline}#{newline}"
post_body << file.size
post_body << "#{newline}--#{boundary}#{newline}"
post_body << "Content-Disposition: form-data; name=\"_currentChunkSize\"#{newline}#{newline}"
post_body << file.size
post_body << "#{newline}--#{boundary}#{newline}"
post_body << "Content-Disposition: form-data; name=\"_currentNumber\"#{newline}#{newline}"
post_body << 0
post_body << "#{newline}--#{boundary}#{newline}"
post_body << "Content-Disposition: form-data; name=\"_totalSize\"#{newline}#{newline}"
post_body << file.size
post_body << "#{newline}--#{boundary}#{newline}"
post_body << "Content-Disposition: form-data; name=\"file\"; filename=\"#{file_path.basename.to_s}\"#{newline}"
post_body << "Content-Type: application/octet-stream#{newline}#{newline}"
post_body << file
post_body << "#{newline}--#{boundary}--#{newline}"
request = Net::HTTP::Post.new(uri.request_uri)
request.body = post_body.join
request["Content-Type"] = "multipart/form-data; boundary=#{boundary}"
request['Content-Length'] = request.body().length
request["TokenId"] = token_id
request["RoomId"] = 7104
http = Net::HTTP.new uri.host, uri.port
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
response = http.request request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment