Skip to content
8 changes: 2 additions & 6 deletions google-cloud-storage/lib/google/cloud/storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ def self.new project_id: nil, credentials: nil, scope: nil, retries: nil,
timeout: nil, open_timeout: nil, read_timeout: nil,
send_timeout: nil, endpoint: nil, project: nil, keyfile: nil,
max_elapsed_time: nil, base_interval: nil, max_interval: nil,
multiplier: nil, upload_chunk_size: nil, universe_domain: nil,
upload_url: nil, delete_upload: nil

multiplier: nil, upload_chunk_size: nil, universe_domain: nil
scope ||= configure.scope
retries ||= configure.retries
timeout ||= configure.timeout
Expand All @@ -111,8 +109,7 @@ def self.new project_id: nil, credentials: nil, scope: nil, retries: nil,
multiplier ||= configure.multiplier
upload_chunk_size ||= configure.upload_chunk_size
universe_domain ||= configure.universe_domain
upload_url ||= configure.upload_url
delete_upload ||= configure.delete_upload

unless credentials.is_a? Google::Auth::Credentials
credentials = Storage::Credentials.new credentials, scope: scope
end
Expand All @@ -128,7 +125,6 @@ def self.new project_id: nil, credentials: nil, scope: nil, retries: nil,
host: endpoint, quota_project: configure.quota_project,
max_elapsed_time: max_elapsed_time, base_interval: base_interval,
max_interval: max_interval, multiplier: multiplier, upload_chunk_size: upload_chunk_size,
upload_url: upload_url, delete_upload: delete_upload,
universe_domain: universe_domain
)
)
Expand Down
41 changes: 41 additions & 0 deletions google-cloud-storage/lib/google/cloud/storage/bucket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,29 @@ def default_kms_key= new_default_kms_key
patch_gapi! :encryption
end

##
# Restart resumable upload
# @param [String, ::File] file Path of the file on the filesystem to
# upload. Can be an File object, or File-like object such as StringIO.
# (If the object does not have path, a `path` argument must be also be
# provided.)
# @param [String] upload_id Unique Id of an resumable upload
#
# @example
# require "google/cloud/storage"
#
# storage = Google::Cloud::Storage.new
#
# bucket = storage.bucket "my-bucket"
# bucket.restart_resumable_upload file,upload_id

def restart_resumable_upload file, upload_id
ensure_service!
ensure_io_or_file_exists! file
raise "Upload Id missing" unless upload_id
service.restart_resumable_upload name, file, upload_id
end

##
# The period of time (in seconds) that files in the bucket must be
# retained, and cannot be deleted, overwritten, or archived.
Expand Down Expand Up @@ -1410,6 +1433,23 @@ def delete if_metageneration_match: nil, if_metageneration_not_match: nil
user_project: user_project
end

##
# Delete resumable upload
# @param [String] upload_id Unique Id of an resumable upload
#
# @example
# require "google/cloud/storage"
#
# storage = Google::Cloud::Storage.new
#
# bucket = storage.bucket "my-bucket"
# bucket.delete_resumable_upload file,upload_id

def delete_resumable_upload upload_id
ensure_service!
raise "Upload Id missing" unless upload_id
service.delete_resumable_upload name, upload_id, options: { delete_upload: true }
end
##
# Retrieves a list of files matching the criteria.
#
Expand Down Expand Up @@ -1465,6 +1505,7 @@ def delete if_metageneration_match: nil, if_metageneration_not_match: nil
# puts file.name
# end
#

def files prefix: nil, delimiter: nil, token: nil, max: nil,
versions: nil, match_glob: nil, include_folders_as_prefixes: nil,
soft_deleted: nil
Expand Down
18 changes: 13 additions & 5 deletions google-cloud-storage/lib/google/cloud/storage/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ def initialize project, credentials, retries: nil,
timeout: nil, open_timeout: nil, read_timeout: nil,
send_timeout: nil, host: nil, quota_project: nil,
max_elapsed_time: nil, base_interval: nil, max_interval: nil,
multiplier: nil, upload_chunk_size: nil, universe_domain: nil,
upload_url: nil, delete_upload: nil

multiplier: nil, upload_chunk_size: nil, universe_domain: nil
host ||= Google::Cloud::Storage.configure.endpoint
@project = project
@credentials = credentials
Expand All @@ -75,8 +73,6 @@ def initialize project, credentials, retries: nil,
@service.request_options.multiplier = multiplier if multiplier
@service.request_options.add_invocation_id_header = true
@service.request_options.upload_chunk_size = upload_chunk_size if upload_chunk_size
@service.request_options.upload_url = upload_url if upload_url
@service.request_options.delete_upload = delete_upload if delete_upload
@service.authorization = @credentials.client if @credentials
@service.root_url = host if host
@service.universe_domain = universe_domain || Google::Cloud::Storage.configure.universe_domain
Expand Down Expand Up @@ -658,6 +654,18 @@ def delete_file bucket_name,
end
end

def restart_resumable_upload bucket_name, source, upload_id, options: {}
execute do
service.restart_resumable_upload bucket_name, source, upload_id, options: options
end
end

def delete_resumable_upload bucket_name, upload_id, options: {}
execute do
service.delete_resumable_upload bucket_name, upload_id, options: options
end
end

##
# Restores a soft-deleted object.
def restore_file bucket_name,
Expand Down
Loading