Merge "Step 14 - very large files."
This commit is contained in:
commit
7f736f886b
@ -3,6 +3,7 @@ require 'fog/openstack'
|
|||||||
require 'digest/md5'
|
require 'digest/md5'
|
||||||
require 'net/http'
|
require 'net/http'
|
||||||
require 'json'
|
require 'json'
|
||||||
|
require 'openuri'
|
||||||
|
|
||||||
# step-1
|
# step-1
|
||||||
auth_username = "your_auth_username"
|
auth_username = "your_auth_username"
|
||||||
@ -82,6 +83,26 @@ object = container.files.create body: File.read(File.expand_path(file_path)),
|
|||||||
metadata: extra
|
metadata: extra
|
||||||
|
|
||||||
# step-14
|
# step-14
|
||||||
#TBC
|
def chunked_file_upload(swift, container_name, object_name, file_path)
|
||||||
|
chunk_size = 4096
|
||||||
|
offset = 0
|
||||||
|
hash = Digest::MD5.hexdigest(File.read(File.expand_path(file_path)))
|
||||||
|
object = swift.put_object(container_name, object_name, nil) do
|
||||||
|
chunk = File.read(file_path, chunk_size, offset)
|
||||||
|
offset += chunk_size
|
||||||
|
chunk ? chunk : ''
|
||||||
|
end
|
||||||
|
unless hash == object.data[:headers]["etag"]
|
||||||
|
swift.delete_object container_name, object_name
|
||||||
|
raise "Checksums do not match. Please retry."
|
||||||
|
end
|
||||||
|
container = swift.directories.get container_name
|
||||||
|
container.files.get object_name
|
||||||
|
end
|
||||||
|
|
||||||
|
object_name = "very_large_file"
|
||||||
|
file_path = "very_large_file"
|
||||||
|
|
||||||
|
object = chunked_file_upload(swift, container_name, object_name, file_path)
|
||||||
|
|
||||||
# step-15
|
# step-15
|
||||||
|
Loading…
x
Reference in New Issue
Block a user