Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Uploadcare::File.remote_copy raising response errors #171

Merged
merged 3 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

### Fixed
* Fixed the `Uploadcare::File.remote_copy` method which raised an `ApiStruct::EntityError: {url} must be Hash`. Now returns a string instead of a `File` entity instance.
### Added
* `Document Info` API added in `DocumentConverter`.
## 4.4.1 — 2024-04-27
Expand Down
6 changes: 3 additions & 3 deletions api_examples/rest_api/post_files_remote_copy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Uploadcare.config.public_key = 'YOUR_PUBLIC_KEY'
Uploadcare.config.secret_key = 'YOUR_SECRET_KEY'

source = '1bac376c-aa7e-4356-861b-dd2657b5bfd2'
source_object = '1bac376c-aa7e-4356-861b-dd2657b5bfd2'
target = 'custom_storage_connected_to_the_project'
copied_file = Uploadcare::File.remote_copy(source, target, make_public: true)
puts copied_file.uuid
copied_file_url = Uploadcare::File.remote_copy(source_object, target, make_public: true)
puts copied_file_url
rsedykh marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion lib/uploadcare/client/multipart_upload_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def upload_complete(uuid)
private

def form_data_for(file)
form_data_file = super(file)
form_data_file = super
{
filename: form_data_file.filename,
size: form_data_file.size,
Expand Down
3 changes: 1 addition & 2 deletions lib/uploadcare/entity/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ def self.local_copy(source, args = {})
#
# @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/File/operation/createRemoteCopy
def self.remote_copy(source, target, args = {})
response = FileClient.new.remote_copy(source: source, target: target, **args).success[:result]
File.new(response)
FileClient.new.remote_copy(source: source, target: target, **args).success[:result]
end

# Instance version of {internal_copy}
Expand Down
115 changes: 115 additions & 0 deletions spec/fixtures/vcr_cassettes/rest_file_remote_copy.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions spec/support/vcr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
VCR.configure do |config|
config.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
config.hook_into :webmock
config.filter_sensitive_data('<uploadcare_public_key>') { Uploadcare.config.public_key }
config.filter_sensitive_data('<uploadcare_secret_key>') { Uploadcare.config.secret_key }
config.before_record do |i|
if i.request.body && i.request.body.size > 1024 * 1024
i.request.body = "Big string (#{i.request.body.size / (1024 * 1024)}) MB"
Expand Down
11 changes: 10 additions & 1 deletion spec/uploadcare/entity/file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,16 @@ module Entity
end

describe 'external_copy' do
it 'copies file to different project' do
it 'copies file to remote storage' do
VCR.use_cassette('rest_file_remote_copy') do
target = 'uploadcare-test'
uuid = '1b959c59-9605-4879-946f-08fdb5ea3e9d'
file = subject.file(uuid)
expect(file.remote_copy(target)).to match(%r{#{target}/#{uuid}/})
end
end

it 'raises an error when project does not have given storage' do
VCR.use_cassette('rest_file_external_copy') do
file = subject.file('5632fc94-9dff-499f-a373-f69ea6f67ff8')
# I don't have custom storage, but this error recognises what this method tries to do
Expand Down
Loading