Class: NVX::SDS::SoapUpload

Inherits:
Object
  • Object
show all
Defined in:
lib/nvx/sds/apiclasses/soapupload.rb

Overview

The SoapTransfer class is used for upload. Since this method doesnt have a specific file size limit other than the 256gb max file size limit this method is used instead of the http upload which is limited to 2gb. This is due to the

Class Method Summary collapse

Class Method Details

.UploadFile(path, local_path, account_login) ⇒ Object

Uploads a file in parts at a using a buffer of 65k.

Usage

session = Session.new(“APP-KEY”, “USERNAME”, “APP NAME”, “PASSWORD”)

SoapUpload.UploadFile(“/path/RemoteFilename.txt”,“C:\localfile.txt”, session.account_login)



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/nvx/sds/apiclasses/soapupload.rb', line 27

def SoapUpload.UploadFile(path, local_path, )
    # Get the Upload node passing in the total file size.
    result = Transport.execute_command_post(APICommand.GetUploadNode, [APIParam.new("sizeBytes", "1000")], )

    # extract the upload token, host name and build a new transfer object.
    upload_token = result.root.elements["//AccessToken"].get_text.value
    node = result.root.elements["//IPAddress"].get_text.value
    # set the URL based on the node that was returned from Nirvanix.
    soap = NVX::SDS::SOAP::TransferSoap.new("http://#{node}/ws/transfer.asmx")
    
    # Open the local file
    file = File.open(local_path, "rb")
    # Loop through the entire file uploading each file part.
    while !file.eof?
        # Send a 65k file part to Nirvanix using the upload token.
        params = NVX::SDS::SOAP::AppendFile.new(upload_token, path, Base64.encode64(file.read(65536)), false)
        soap.appendFile(params)
    end
    # Send an empty data with a True for last packet, this finalizes the upload and will
    # make the file available for download.
    params = NVX::SDS::SOAP::AppendFile.new(upload_token, path, nil, true)
    soap.appendFile(params)
end