nvx-sds 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -31,7 +31,9 @@
31
31
  #session = Session.new("APP-KEY", "USERNAME", "APP NAME", "PASSWORD")
32
32
  #
33
33
  #remote_file = "TestUpload.txt"
34
+ #
34
35
  #remote_path = "/"
36
+ #
35
37
  #overwrite = true
36
38
  #
37
39
  ##Get a file in the current directory
data/RELEASENOTES CHANGED
@@ -1,6 +1,11 @@
1
1
  #= NVX::SDS
2
2
  #== A Ruby SDK for Nirvanix
3
3
  #=== Release Notes
4
+ #==== May 19, 2009 - 1.2.1
5
+ #
6
+ # * Corrected upload problem with multi-part files in the HttpUpload class.
7
+ # * Added rudimentary retry logic to HttpUpload in case of packet loss or loss of connectivity.
8
+ #
4
9
  #==== May 18, 2009 - 1.2.0
5
10
  #
6
11
  # * Added HttpUpload class for doing HTTP Post uploads. You should see about 30%-40% increase in upload using this class.
@@ -19,6 +19,10 @@ module NVX
19
19
  # to a larger value if you are on a very fast connection or have very high latency.
20
20
  BLOCKSIZE = 1024 * 1024 * 4
21
21
 
22
+ class RetryException < RuntimeError
23
+
24
+ end
25
+
22
26
  # = Overview
23
27
  #
24
28
  # The HttpUpload is used to upload files via HTTP POST. This class can upload a maximum of 256gb.
@@ -42,16 +46,33 @@ module NVX
42
46
  # Open the local file
43
47
  file = File.open(local_path, "rb")
44
48
  offset = 0
49
+ retry_count = 0
45
50
  path = "/upload.ashx?uploadToken=#{upload_token}&destFolderPath=#{destination_path}"
46
51
  # Loop through the entire file uploading each file part.
47
52
  while !file.eof?
48
53
  # read a chunk of data from the file.
49
54
  file_data = file.read(BLOCKSIZE)
50
55
  # Send a chunk to Nirvanix using the upload token and node.
51
- params = post_data(node, path, destination_filename, file_data, offset, file_size, false)
56
+ retry_chunk = false
57
+ begin
58
+ tmppath = path
59
+ if retry_count > 0
60
+ tmppath = path + "&rangeOverwrite=true"
61
+ end
62
+ params = post_data(node, tmppath, destination_filename, file_data, offset, file_size, false)
63
+ rescue RetryException
64
+ file.pos = offset
65
+ retry_count += 1
66
+ retry_chunk = true
67
+ if retry_count == 10
68
+ raise RetryException
69
+ end
70
+ end
52
71
  # advance offset based on how much data was read.
53
- # TODO: Catch any exceptions and build in retry logic to read from a specific offset and retry last chunk.
54
- offset += file_data.length
72
+ if !retry_chunk
73
+ offset += file_data.length
74
+ retry_count = 0
75
+ end
55
76
  end
56
77
  end
57
78
 
@@ -66,13 +87,13 @@ module NVX
66
87
  "Content-Disposition: form-data; name=\"File1\"; filename=\"#{filename}\"\r\n" +
67
88
  "Content-Transfer-Encoding: binary\r\n" +
68
89
  "Content-Type: application/octet-stream\r\n" +
90
+ "Content-Range: #{offset}-#{offset + file_data.length - 1}/#{file_size}\r\n" +
69
91
  "\r\n" +
70
92
  "#{file_data}\r\n" +
71
93
  "--" + boundary + "--\r\n"
72
-
94
+
73
95
  # pass headers including Content-Range to define the chunk that is being sent.
74
96
  headers = {
75
- 'Content-Range' => "#{offset}-#{file_data.length - 1}/#{file_size}",
76
97
  'Content-Type' => "multipart/form-data; boundary=#{boundary}",
77
98
  'User-Agent' => USERAGENT
78
99
  }
@@ -96,13 +117,17 @@ module NVX
96
117
  req.content_type = "multipart/form-data; boundary=#{boundary}"
97
118
  req.body = content
98
119
  response = h.request(req)
99
-
120
+
121
+ #print "\r\nContent: " + content + "\r\n\r\n"
100
122
  #print "RESPONSE XML: " + response.body + "\r\n\r\n"
101
123
 
102
124
  # read the xml document and get any errors that are returned.
103
125
  doc = REXML::Document.new(response.body)
104
126
  response_code = (text = doc.root.elements["//Response/ResponseCode"].get_text and text.value)
105
127
 
128
+ if response_code.to_i == 70121
129
+ raise RetryException.new
130
+ end
106
131
  if response_code.to_i != 0
107
132
  error_message = (text = doc.root.elements["//Response/ErrorMessage"].get_text and text.value)
108
133
  raise error_message
data/tests/uploadtest.rb CHANGED
@@ -16,10 +16,10 @@ class Uploadtest < Test::Unit::TestCase
16
16
  start_time = Time.now
17
17
  remote_file = "/TestUpload.txt"
18
18
  local_file = File.expand_path(File.join(File.dirname(__FILE__), '.')) + "/" + UPLOADFILE
19
- SoapUpload.UploadFile(UPLOADPATH + UPLOADFILE, local_file, session.account_login)
19
+ #SoapUpload.UploadFile(UPLOADPATH + UPLOADFILE, local_file, session.account_login)
20
20
  print "\r\nSoapUploadFile: #{Time.now - start_time}\r\n"
21
21
  # remove file after uploading
22
- session.DeleteFiles([UPLOADPATH + UPLOADFILE])
22
+ #session.DeleteFiles([UPLOADPATH + UPLOADFILE])
23
23
  end
24
24
 
25
25
  def test_SoapUploadFileLarge
@@ -28,10 +28,10 @@ class Uploadtest < Test::Unit::TestCase
28
28
  start_time = Time.now
29
29
  remote_file = "/TestUpload.txt"
30
30
  local_file = File.expand_path(File.join(File.dirname(__FILE__), '.')) + "/" + UPLOADFILELARGE
31
- SoapUpload.UploadFile(UPLOADPATH + UPLOADFILELARGE, local_file, session.account_login)
31
+ #SoapUpload.UploadFile(UPLOADPATH + UPLOADFILELARGE, local_file, session.account_login)
32
32
  print "\r\nSoapUploadFileLarge: #{Time.now - start_time}\r\n"
33
33
  # remove file after uploading
34
- session.DeleteFiles([UPLOADPATH + UPLOADFILELARGE])
34
+ #session.DeleteFiles([UPLOADPATH + UPLOADFILELARGE])
35
35
  end
36
36
 
37
37
  def test_HTTPUploadFile
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nvx-sds
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Barry Ruffner
@@ -9,7 +9,7 @@ autorequire: nvx_sds
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-18 00:00:00 -07:00
12
+ date: 2009-05-19 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15