uploadcare-ruby 4.4.3 → 5.0.0.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.env.example +7 -0
- data/.github/workflows/gem-push.yml +1 -1
- data/.github/workflows/ruby.yml +10 -13
- data/.gitignore +9 -0
- data/.rubocop.yml +95 -8
- data/CHANGELOG.md +71 -1
- data/Gemfile +23 -6
- data/MIGRATING_V5.md +290 -0
- data/README.md +422 -671
- data/Rakefile +5 -1
- data/api_examples/README.md +77 -0
- data/api_examples/rest_api/delete_files_storage.rb +3 -5
- data/api_examples/rest_api/delete_files_uuid_metadata_key.rb +3 -4
- data/api_examples/rest_api/delete_files_uuid_storage.rb +3 -4
- data/api_examples/rest_api/delete_groups_uuid.rb +3 -4
- data/api_examples/rest_api/delete_webhooks_unsubscribe.rb +3 -4
- data/api_examples/rest_api/get_addons_aws_rekognition_detect_labels_execute_status.rb +3 -6
- data/api_examples/rest_api/get_addons_aws_rekognition_detect_moderation_labels_execute_status.rb +3 -6
- data/api_examples/rest_api/get_addons_remove_bg_execute_status.rb +3 -6
- data/api_examples/rest_api/get_addons_uc_clamav_virus_scan_execute_status.rb +3 -6
- data/api_examples/rest_api/get_convert_document_status_token.rb +3 -5
- data/api_examples/rest_api/get_convert_document_uuid.rb +3 -5
- data/api_examples/rest_api/get_convert_video_status_token.rb +3 -5
- data/api_examples/rest_api/get_files.rb +3 -5
- data/api_examples/rest_api/get_files_uuid.rb +3 -5
- data/api_examples/rest_api/get_files_uuid_metadata.rb +3 -5
- data/api_examples/rest_api/get_files_uuid_metadata_key.rb +3 -5
- data/api_examples/rest_api/get_groups.rb +3 -5
- data/api_examples/rest_api/get_groups_uuid.rb +3 -5
- data/api_examples/rest_api/get_project.rb +3 -5
- data/api_examples/rest_api/get_webhooks.rb +3 -5
- data/api_examples/rest_api/post_addons_aws_rekognition_detect_labels_execute.rb +3 -5
- data/api_examples/rest_api/post_addons_aws_rekognition_detect_moderation_labels_execute.rb +3 -5
- data/api_examples/rest_api/post_addons_remove_bg_execute.rb +3 -5
- data/api_examples/rest_api/post_addons_uc_clamav_virus_scan_execute.rb +3 -5
- data/api_examples/rest_api/post_convert_document.rb +3 -8
- data/api_examples/rest_api/post_convert_video.rb +3 -10
- data/api_examples/rest_api/post_files_local_copy.rb +3 -6
- data/api_examples/rest_api/post_files_remote_copy.rb +3 -7
- data/api_examples/rest_api/post_webhooks.rb +3 -9
- data/api_examples/rest_api/put_files_storage.rb +3 -8
- data/api_examples/rest_api/put_files_uuid_metadata_key.rb +3 -7
- data/api_examples/rest_api/put_files_uuid_storage.rb +3 -5
- data/api_examples/rest_api/put_webhooks_id.rb +3 -11
- data/api_examples/support/example_helper.rb +250 -0
- data/api_examples/support/run_rest_example.rb +161 -0
- data/api_examples/support/run_upload_example.rb +88 -0
- data/api_examples/upload_api/get_from_url_status.rb +3 -5
- data/api_examples/upload_api/get_group_info.rb +3 -6
- data/api_examples/upload_api/get_info.rb +3 -6
- data/api_examples/upload_api/post_base.rb +3 -5
- data/api_examples/upload_api/post_from_url.rb +3 -5
- data/api_examples/upload_api/post_group.rb +3 -8
- data/api_examples/upload_api/post_multipart_complete.rb +3 -7
- data/api_examples/upload_api/post_multipart_start.rb +3 -7
- data/api_examples/upload_api/put_multipart_part.rb +4 -0
- data/bin/console +1 -1
- data/docs/release-notes-5.0.0.rc1.md +34 -0
- data/examples/README.md +39 -0
- data/examples/batch_upload.rb +54 -0
- data/examples/group_creation.rb +88 -0
- data/examples/large_file_upload.rb +88 -0
- data/examples/simple_upload.rb +39 -0
- data/examples/upload_with_progress.rb +84 -0
- data/examples/url_upload.rb +56 -0
- data/lib/uploadcare/api/rest/addons.rb +107 -0
- data/lib/uploadcare/api/rest/document_conversions.rb +65 -0
- data/lib/uploadcare/api/rest/file_metadata.rb +71 -0
- data/lib/uploadcare/api/rest/files.rb +112 -0
- data/lib/uploadcare/api/rest/groups.rb +49 -0
- data/lib/uploadcare/api/rest/project.rb +23 -0
- data/lib/uploadcare/api/rest/video_conversions.rb +52 -0
- data/lib/uploadcare/api/rest/webhooks.rb +74 -0
- data/lib/uploadcare/api/rest.rb +254 -0
- data/lib/uploadcare/api/upload/files.rb +313 -0
- data/lib/uploadcare/api/upload/groups.rb +72 -0
- data/lib/uploadcare/api/upload.rb +272 -0
- data/lib/uploadcare/client/addons_accessor.rb +85 -0
- data/lib/uploadcare/client/api.rb +33 -0
- data/lib/uploadcare/client/conversions_accessor.rb +33 -0
- data/lib/uploadcare/client/document_conversions_accessor.rb +41 -0
- data/lib/uploadcare/client/file_metadata_accessor.rb +46 -0
- data/lib/uploadcare/client/files_accessor.rb +82 -0
- data/lib/uploadcare/client/groups_accessor.rb +35 -0
- data/lib/uploadcare/client/project_accessor.rb +17 -0
- data/lib/uploadcare/client/video_conversions_accessor.rb +33 -0
- data/lib/uploadcare/client/webhooks_accessor.rb +42 -0
- data/lib/uploadcare/client.rb +127 -0
- data/lib/uploadcare/cname_generator.rb +68 -0
- data/lib/uploadcare/collections/batch_result.rb +35 -0
- data/lib/uploadcare/collections/paginated.rb +165 -0
- data/lib/uploadcare/configuration.rb +81 -0
- data/lib/uploadcare/exception/auth_error.rb +2 -6
- data/lib/uploadcare/exception/configuration_error.rb +4 -0
- data/lib/uploadcare/exception/conversion_error.rb +2 -6
- data/lib/uploadcare/exception/invalid_request_error.rb +4 -0
- data/lib/uploadcare/exception/multipart_upload_error.rb +4 -0
- data/lib/uploadcare/exception/not_found_error.rb +4 -0
- data/lib/uploadcare/exception/request_error.rb +2 -6
- data/lib/uploadcare/exception/retry_error.rb +2 -6
- data/lib/uploadcare/exception/throttle_error.rb +7 -11
- data/lib/uploadcare/exception/unknown_status_error.rb +4 -0
- data/lib/uploadcare/exception/upload_error.rb +4 -0
- data/lib/uploadcare/exception/upload_timeout_error.rb +4 -0
- data/lib/uploadcare/internal/authenticator.rb +101 -0
- data/lib/uploadcare/internal/error_handler.rb +102 -0
- data/lib/uploadcare/internal/signature_generator.rb +31 -0
- data/lib/uploadcare/internal/throttle_handler.rb +36 -0
- data/lib/uploadcare/internal/upload_io.rb +110 -0
- data/lib/uploadcare/internal/upload_params_generator.rb +86 -0
- data/lib/uploadcare/internal/user_agent.rb +22 -0
- data/lib/uploadcare/operations/multipart_upload.rb +213 -0
- data/lib/uploadcare/operations/upload_router.rb +162 -0
- data/lib/uploadcare/resources/addon_execution.rb +97 -0
- data/lib/uploadcare/resources/base_resource.rb +61 -0
- data/lib/uploadcare/resources/document_conversion.rb +81 -0
- data/lib/uploadcare/resources/file.rb +366 -0
- data/lib/uploadcare/resources/file_metadata.rb +135 -0
- data/lib/uploadcare/resources/group.rb +142 -0
- data/lib/uploadcare/resources/project.rb +26 -0
- data/lib/uploadcare/resources/video_conversion.rb +59 -0
- data/lib/uploadcare/resources/webhook.rb +85 -0
- data/lib/uploadcare/result.rb +85 -0
- data/lib/uploadcare/signed_url_generators/akamai_generator.rb +50 -51
- data/lib/uploadcare/signed_url_generators/base_generator.rb +15 -15
- data/lib/uploadcare/version.rb +7 -0
- data/lib/uploadcare/webhook_signature_verifier.rb +60 -0
- data/lib/uploadcare.rb +84 -50
- data/mise.toml +2 -0
- data/uploadcare-ruby.gemspec +8 -7
- metadata +102 -74
- data/api_examples/upload_api/put_presigned_url_x.rb +0 -8
- data/lib/uploadcare/api/api.rb +0 -25
- data/lib/uploadcare/client/addons_client.rb +0 -69
- data/lib/uploadcare/client/conversion/base_conversion_client.rb +0 -60
- data/lib/uploadcare/client/conversion/document_conversion_client.rb +0 -45
- data/lib/uploadcare/client/conversion/video_conversion_client.rb +0 -46
- data/lib/uploadcare/client/file_client.rb +0 -48
- data/lib/uploadcare/client/file_list_client.rb +0 -46
- data/lib/uploadcare/client/file_metadata_client.rb +0 -36
- data/lib/uploadcare/client/group_client.rb +0 -45
- data/lib/uploadcare/client/multipart_upload/chunks_client.rb +0 -58
- data/lib/uploadcare/client/multipart_upload_client.rb +0 -64
- data/lib/uploadcare/client/project_client.rb +0 -20
- data/lib/uploadcare/client/rest_client.rb +0 -77
- data/lib/uploadcare/client/rest_group_client.rb +0 -43
- data/lib/uploadcare/client/upload_client.rb +0 -46
- data/lib/uploadcare/client/uploader_client.rb +0 -128
- data/lib/uploadcare/client/webhook_client.rb +0 -49
- data/lib/uploadcare/concern/error_handler.rb +0 -54
- data/lib/uploadcare/concern/throttle_handler.rb +0 -25
- data/lib/uploadcare/concern/upload_error_handler.rb +0 -32
- data/lib/uploadcare/entity/addons.rb +0 -14
- data/lib/uploadcare/entity/conversion/base_converter.rb +0 -43
- data/lib/uploadcare/entity/conversion/document_converter.rb +0 -15
- data/lib/uploadcare/entity/conversion/video_converter.rb +0 -15
- data/lib/uploadcare/entity/decorator/paginator.rb +0 -79
- data/lib/uploadcare/entity/entity.rb +0 -18
- data/lib/uploadcare/entity/file.rb +0 -103
- data/lib/uploadcare/entity/file_list.rb +0 -32
- data/lib/uploadcare/entity/file_metadata.rb +0 -30
- data/lib/uploadcare/entity/group.rb +0 -49
- data/lib/uploadcare/entity/group_list.rb +0 -24
- data/lib/uploadcare/entity/project.rb +0 -13
- data/lib/uploadcare/entity/uploader.rb +0 -93
- data/lib/uploadcare/entity/webhook.rb +0 -14
- data/lib/uploadcare/param/authentication_header.rb +0 -37
- data/lib/uploadcare/param/conversion/document/processing_job_url_builder.rb +0 -39
- data/lib/uploadcare/param/conversion/video/processing_job_url_builder.rb +0 -64
- data/lib/uploadcare/param/param.rb +0 -10
- data/lib/uploadcare/param/secure_auth_header.rb +0 -51
- data/lib/uploadcare/param/simple_auth_header.rb +0 -14
- data/lib/uploadcare/param/upload/signature_generator.rb +0 -24
- data/lib/uploadcare/param/upload/upload_params_generator.rb +0 -41
- data/lib/uploadcare/param/user_agent.rb +0 -21
- data/lib/uploadcare/param/webhook_signature_verifier.rb +0 -23
- data/lib/uploadcare/ruby/version.rb +0 -5
data/examples/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Workflow Examples
|
|
2
|
+
|
|
3
|
+
This directory contains higher-level workflow demos built on the public client API.
|
|
4
|
+
|
|
5
|
+
For endpoint-by-endpoint coverage, use [api_examples/README.md](../api_examples/README.md).
|
|
6
|
+
|
|
7
|
+
## Setup
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
export UPLOADCARE_PUBLIC_KEY=your_public_key
|
|
11
|
+
export UPLOADCARE_SECRET_KEY=your_secret_key
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Run scripts with project-managed Ruby:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
mise exec -- ruby examples/simple_upload.rb spec/fixtures/kitten.jpeg
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Scripts
|
|
21
|
+
|
|
22
|
+
- `examples/simple_upload.rb`
|
|
23
|
+
Upload one file and print its UUID and CDN URL.
|
|
24
|
+
- `examples/upload_with_progress.rb`
|
|
25
|
+
Upload one large file with multipart progress reporting.
|
|
26
|
+
- `examples/batch_upload.rb`
|
|
27
|
+
Upload multiple files in one call.
|
|
28
|
+
- `examples/large_file_upload.rb`
|
|
29
|
+
Force multipart upload and show throughput details.
|
|
30
|
+
- `examples/url_upload.rb`
|
|
31
|
+
Upload a remote URL and show async polling as a follow-up example.
|
|
32
|
+
- `examples/group_creation.rb`
|
|
33
|
+
Upload multiple files, create a group, and print group details.
|
|
34
|
+
|
|
35
|
+
## Notes
|
|
36
|
+
|
|
37
|
+
- These are workflow demos.
|
|
38
|
+
- The canonical API inventory lives in `api_examples/`.
|
|
39
|
+
- The examples assume real Uploadcare credentials and network access.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative '../lib/uploadcare'
|
|
5
|
+
require 'dotenv/load'
|
|
6
|
+
|
|
7
|
+
file_paths = ARGV
|
|
8
|
+
|
|
9
|
+
if file_paths.empty?
|
|
10
|
+
puts 'Usage: ruby batch_upload.rb <file1> <file2> <file3> ...'
|
|
11
|
+
puts 'Example: ruby batch_upload.rb photo1.jpg photo2.jpg photo3.jpg'
|
|
12
|
+
exit 1
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
file_paths.each do |path|
|
|
16
|
+
unless File.exist?(path)
|
|
17
|
+
puts "Error: File not found: #{path}"
|
|
18
|
+
exit 1
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
puts "Batch Upload - #{file_paths.length} files"
|
|
23
|
+
puts '=' * 50
|
|
24
|
+
puts
|
|
25
|
+
|
|
26
|
+
files = file_paths.map { |path| File.open(path, 'rb') }
|
|
27
|
+
|
|
28
|
+
begin
|
|
29
|
+
client = Uploadcare::Client.new(
|
|
30
|
+
public_key: ENV.fetch('UPLOADCARE_PUBLIC_KEY'),
|
|
31
|
+
secret_key: ENV.fetch('UPLOADCARE_SECRET_KEY')
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
results = client.uploads.upload(files, store: true)
|
|
35
|
+
|
|
36
|
+
puts '✓ Batch upload complete!'
|
|
37
|
+
puts
|
|
38
|
+
puts 'Results:'
|
|
39
|
+
puts '-' * 50
|
|
40
|
+
|
|
41
|
+
results.each_with_index do |file, index|
|
|
42
|
+
puts "#{index + 1}. #{file.original_filename}"
|
|
43
|
+
puts " UUID: #{file.uuid}"
|
|
44
|
+
puts " CDN URL: #{file.cdn_url}"
|
|
45
|
+
puts
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
puts "Successfully uploaded #{results.length} files"
|
|
49
|
+
rescue StandardError => e
|
|
50
|
+
puts "✗ Batch upload failed: #{e.message}"
|
|
51
|
+
exit 1
|
|
52
|
+
ensure
|
|
53
|
+
files.each(&:close)
|
|
54
|
+
end
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative '../lib/uploadcare'
|
|
5
|
+
require 'dotenv/load'
|
|
6
|
+
|
|
7
|
+
file_paths = ARGV
|
|
8
|
+
|
|
9
|
+
if file_paths.empty?
|
|
10
|
+
script_name = File.basename($PROGRAM_NAME)
|
|
11
|
+
puts "Usage: ruby examples/#{script_name} <file1> <file2> <file3> ..."
|
|
12
|
+
puts "Example: ruby examples/#{script_name} photo1.jpg photo2.jpg photo3.jpg"
|
|
13
|
+
exit 1
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
file_paths.each do |path|
|
|
17
|
+
unless File.exist?(path)
|
|
18
|
+
puts "Error: File not found: #{path}"
|
|
19
|
+
exit 1
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
puts "Group Creation - #{file_paths.length} files"
|
|
24
|
+
puts '=' * 50
|
|
25
|
+
puts
|
|
26
|
+
|
|
27
|
+
begin
|
|
28
|
+
client = Uploadcare::Client.new(
|
|
29
|
+
public_key: ENV.fetch('UPLOADCARE_PUBLIC_KEY'),
|
|
30
|
+
secret_key: ENV.fetch('UPLOADCARE_SECRET_KEY')
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
puts 'Step 1: Uploading files...'
|
|
34
|
+
uuids = []
|
|
35
|
+
|
|
36
|
+
file_paths.each_with_index do |path, index|
|
|
37
|
+
uploaded = File.open(path, 'rb') do |file|
|
|
38
|
+
client.files.upload(file, store: true)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
uuids << uploaded.uuid
|
|
42
|
+
puts " #{index + 1}. #{File.basename(path)} → #{uploaded.uuid}"
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
puts
|
|
46
|
+
puts "✓ Uploaded #{uuids.length} files"
|
|
47
|
+
puts
|
|
48
|
+
|
|
49
|
+
puts 'Step 2: Creating group...'
|
|
50
|
+
group = client.groups.create(uuids: uuids)
|
|
51
|
+
|
|
52
|
+
puts '✓ Group created!'
|
|
53
|
+
puts
|
|
54
|
+
puts 'Group Details:'
|
|
55
|
+
puts '-' * 50
|
|
56
|
+
puts "Group ID: #{group.id}"
|
|
57
|
+
puts "Files count: #{group.files_count}"
|
|
58
|
+
puts "CDN URL: #{group.cdn_url}"
|
|
59
|
+
puts "Created at: #{group.datetime_created}"
|
|
60
|
+
puts
|
|
61
|
+
|
|
62
|
+
puts 'Step 3: Retrieving group info...'
|
|
63
|
+
info = client.groups.find(group_id: group.id)
|
|
64
|
+
|
|
65
|
+
puts '✓ Group info retrieved'
|
|
66
|
+
puts
|
|
67
|
+
puts 'Files in group:'
|
|
68
|
+
puts '-' * 50
|
|
69
|
+
|
|
70
|
+
Array(info.files).each_with_index do |file, index|
|
|
71
|
+
file_resource = Uploadcare::Resources::File.new(file, client)
|
|
72
|
+
puts "#{index + 1}. #{file_resource.original_filename}"
|
|
73
|
+
puts " UUID: #{file_resource.uuid}"
|
|
74
|
+
puts " Size: #{(file_resource.size / 1024.0).round(2)} KB"
|
|
75
|
+
puts " URL: #{file_resource.cdn_url}"
|
|
76
|
+
puts
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
puts 'Group URL:'
|
|
80
|
+
puts group.cdn_url
|
|
81
|
+
puts
|
|
82
|
+
puts 'You can access individual files in the group:'
|
|
83
|
+
puts "#{group.cdn_url}nth/0/"
|
|
84
|
+
puts "#{group.cdn_url}nth/1/"
|
|
85
|
+
rescue StandardError => e
|
|
86
|
+
puts "✗ Group creation failed: #{e.message}"
|
|
87
|
+
exit 1
|
|
88
|
+
end
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative '../lib/uploadcare'
|
|
5
|
+
require 'dotenv/load'
|
|
6
|
+
|
|
7
|
+
file_path = ARGV[0]
|
|
8
|
+
threads = (ARGV[1] || 4).to_i
|
|
9
|
+
|
|
10
|
+
unless file_path && File.exist?(file_path)
|
|
11
|
+
puts 'Usage: ruby large_file_upload.rb <file_path> [threads]'
|
|
12
|
+
puts 'Example: ruby large_file_upload.rb large_video.mp4 4'
|
|
13
|
+
puts
|
|
14
|
+
puts 'threads: Number of parallel upload threads (default: 4)'
|
|
15
|
+
exit 1
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
file_size = File.size(file_path)
|
|
19
|
+
file_size_mb = (file_size / 1024.0 / 1024.0).round(2)
|
|
20
|
+
|
|
21
|
+
if file_size < 10_000_000
|
|
22
|
+
puts 'Warning: File is < 10MB. Multipart upload is recommended for files >= 10MB'
|
|
23
|
+
puts 'The upload will still work but may use base upload instead.'
|
|
24
|
+
puts
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
puts 'Large File Upload'
|
|
28
|
+
puts '=' * 50
|
|
29
|
+
puts "File: #{file_path}"
|
|
30
|
+
puts "Size: #{file_size_mb} MB"
|
|
31
|
+
puts "Threads: #{threads}"
|
|
32
|
+
puts
|
|
33
|
+
|
|
34
|
+
begin
|
|
35
|
+
client = Uploadcare::Client.new(
|
|
36
|
+
public_key: ENV.fetch('UPLOADCARE_PUBLIC_KEY'),
|
|
37
|
+
secret_key: ENV.fetch('UPLOADCARE_SECRET_KEY')
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
start_time = Time.now
|
|
41
|
+
result = nil
|
|
42
|
+
|
|
43
|
+
File.open(file_path, 'rb') do |file|
|
|
44
|
+
result = client.uploads.multipart_upload(
|
|
45
|
+
file: file,
|
|
46
|
+
store: true,
|
|
47
|
+
threads: threads,
|
|
48
|
+
metadata: {
|
|
49
|
+
source: 'large_file_example',
|
|
50
|
+
upload_method: 'multipart'
|
|
51
|
+
}
|
|
52
|
+
) do |progress|
|
|
53
|
+
uploaded_mb = (progress[:uploaded] / 1024.0 / 1024.0).round(2)
|
|
54
|
+
total_mb = (progress[:total] / 1024.0 / 1024.0).round(2)
|
|
55
|
+
percentage = ((progress[:uploaded].to_f / progress[:total]) * 100).round
|
|
56
|
+
part = progress[:part]
|
|
57
|
+
total_parts = progress[:total_parts]
|
|
58
|
+
|
|
59
|
+
bar_length = 30
|
|
60
|
+
filled = (bar_length * percentage / 100).to_i
|
|
61
|
+
bar = ('#' * filled) + ('.' * (bar_length - filled))
|
|
62
|
+
|
|
63
|
+
print "\r#{bar} #{percentage}% | Part #{part}/#{total_parts} | #{uploaded_mb}/#{total_mb} MB"
|
|
64
|
+
$stdout.flush
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
elapsed = Time.now - start_time
|
|
69
|
+
|
|
70
|
+
puts
|
|
71
|
+
puts
|
|
72
|
+
puts '✓ Upload successful!'
|
|
73
|
+
puts
|
|
74
|
+
puts 'Upload Details:'
|
|
75
|
+
puts '-' * 50
|
|
76
|
+
puts "UUID: #{result.uuid}"
|
|
77
|
+
puts "Size: #{file_size_mb} MB"
|
|
78
|
+
puts "Time: #{elapsed.round(2)} seconds"
|
|
79
|
+
puts "Speed: #{(file_size_mb / elapsed).round(2)} MB/s"
|
|
80
|
+
puts "Threads: #{threads}"
|
|
81
|
+
puts 'Method: Multipart upload'
|
|
82
|
+
puts
|
|
83
|
+
puts "CDN URL: #{result.cdn_url}"
|
|
84
|
+
rescue StandardError => e
|
|
85
|
+
puts
|
|
86
|
+
puts "✗ Upload failed: #{e.message}"
|
|
87
|
+
exit 1
|
|
88
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative '../lib/uploadcare'
|
|
5
|
+
require 'dotenv/load'
|
|
6
|
+
|
|
7
|
+
file_path = ARGV[0]
|
|
8
|
+
|
|
9
|
+
unless file_path && File.exist?(file_path)
|
|
10
|
+
puts 'Usage: ruby simple_upload.rb <file_path>'
|
|
11
|
+
puts 'Example: ruby simple_upload.rb photo.jpg'
|
|
12
|
+
exit 1
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
puts "Uploading: #{file_path}"
|
|
16
|
+
puts "Size: #{(File.size(file_path) / 1024.0).round(2)} KB"
|
|
17
|
+
puts
|
|
18
|
+
|
|
19
|
+
begin
|
|
20
|
+
client = Uploadcare::Client.new(
|
|
21
|
+
public_key: ENV.fetch('UPLOADCARE_PUBLIC_KEY'),
|
|
22
|
+
secret_key: ENV.fetch('UPLOADCARE_SECRET_KEY')
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
uploaded_file = File.open(file_path, 'rb') do |file|
|
|
26
|
+
client.files.upload(file, store: true)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
puts '✓ Upload successful!'
|
|
30
|
+
puts
|
|
31
|
+
puts "UUID: #{uploaded_file.uuid}"
|
|
32
|
+
puts "Filename: #{uploaded_file.original_filename}"
|
|
33
|
+
puts "CDN URL: #{uploaded_file.cdn_url}"
|
|
34
|
+
puts
|
|
35
|
+
puts 'The file has been stored and is ready to use.'
|
|
36
|
+
rescue StandardError => e
|
|
37
|
+
puts "✗ Upload failed: #{e.message}"
|
|
38
|
+
exit 1
|
|
39
|
+
end
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative '../lib/uploadcare'
|
|
5
|
+
require 'dotenv/load'
|
|
6
|
+
|
|
7
|
+
file_path = ARGV[0]
|
|
8
|
+
script_name = File.basename($PROGRAM_NAME)
|
|
9
|
+
multipart_threshold = 10 * 1024 * 1024
|
|
10
|
+
|
|
11
|
+
unless file_path && File.exist?(file_path)
|
|
12
|
+
puts "Usage: ruby examples/#{script_name} <file_path>"
|
|
13
|
+
puts "Example: ruby examples/#{script_name} large_video.mp4"
|
|
14
|
+
puts
|
|
15
|
+
puts 'Note: Progress tracking works best with files >= 10 MiB'
|
|
16
|
+
exit 1
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
file_size = File.size(file_path)
|
|
20
|
+
file_size_mb = (file_size / 1024.0 / 1024.0).round(2)
|
|
21
|
+
|
|
22
|
+
puts "Uploading: #{file_path}"
|
|
23
|
+
puts "Size: #{file_size_mb} MB"
|
|
24
|
+
puts
|
|
25
|
+
|
|
26
|
+
if file_size < multipart_threshold
|
|
27
|
+
puts 'Note: File is < 10 MiB, so the upload may complete without multipart progress updates'
|
|
28
|
+
puts
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
file = nil
|
|
32
|
+
|
|
33
|
+
begin
|
|
34
|
+
client = Uploadcare::Client.new(
|
|
35
|
+
public_key: ENV.fetch('UPLOADCARE_PUBLIC_KEY'),
|
|
36
|
+
secret_key: ENV.fetch('UPLOADCARE_SECRET_KEY')
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
file = File.open(file_path, 'rb')
|
|
40
|
+
start_time = Time.now
|
|
41
|
+
|
|
42
|
+
result = client.uploads.upload(file, store: true) do |progress|
|
|
43
|
+
uploaded_mb = (progress[:uploaded] / 1024.0 / 1024.0).round(2)
|
|
44
|
+
total_mb = (progress[:total] / 1024.0 / 1024.0).round(2)
|
|
45
|
+
percentage = ((progress[:uploaded].to_f / progress[:total]) * 100).round
|
|
46
|
+
part = progress[:part]
|
|
47
|
+
total_parts = progress[:total_parts]
|
|
48
|
+
|
|
49
|
+
elapsed = Time.now - start_time
|
|
50
|
+
speed_mbps = uploaded_mb / elapsed
|
|
51
|
+
remaining_mb = total_mb - uploaded_mb
|
|
52
|
+
eta_seconds = remaining_mb / speed_mbps if speed_mbps.positive?
|
|
53
|
+
|
|
54
|
+
bar_length = 40
|
|
55
|
+
filled = (bar_length * percentage / 100).to_i
|
|
56
|
+
bar = ('#' * filled) + ('.' * (bar_length - filled))
|
|
57
|
+
|
|
58
|
+
print "\r#{bar} #{percentage}% | "
|
|
59
|
+
print "#{uploaded_mb}/#{total_mb} MB | "
|
|
60
|
+
print "Part #{part}/#{total_parts} | "
|
|
61
|
+
print "Speed: #{speed_mbps.round(2)} MB/s"
|
|
62
|
+
print " | ETA: #{eta_seconds.to_i}s" if eta_seconds
|
|
63
|
+
$stdout.flush
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
elapsed = Time.now - start_time
|
|
67
|
+
|
|
68
|
+
puts
|
|
69
|
+
puts
|
|
70
|
+
puts '✓ Upload successful!'
|
|
71
|
+
puts
|
|
72
|
+
puts "UUID: #{result.uuid}"
|
|
73
|
+
puts "Filename: #{result.original_filename}"
|
|
74
|
+
puts "Total time: #{elapsed.round(2)} seconds"
|
|
75
|
+
puts "Average speed: #{(file_size_mb / elapsed).round(2)} MB/s"
|
|
76
|
+
puts
|
|
77
|
+
puts "CDN URL: #{result.cdn_url}"
|
|
78
|
+
rescue StandardError => e
|
|
79
|
+
puts
|
|
80
|
+
puts "✗ Upload failed: #{e.message}"
|
|
81
|
+
exit 1
|
|
82
|
+
ensure
|
|
83
|
+
file&.close
|
|
84
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative '../lib/uploadcare'
|
|
5
|
+
require 'dotenv/load'
|
|
6
|
+
|
|
7
|
+
url = ARGV[0]
|
|
8
|
+
|
|
9
|
+
unless url&.match?(%r{^https?://})
|
|
10
|
+
puts 'Usage: ruby url_upload.rb <url>'
|
|
11
|
+
puts 'Example: ruby url_upload.rb https://example.com/image.jpg'
|
|
12
|
+
exit 1
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
puts 'URL Upload'
|
|
16
|
+
puts '=' * 50
|
|
17
|
+
puts "URL: #{url}"
|
|
18
|
+
puts
|
|
19
|
+
|
|
20
|
+
begin
|
|
21
|
+
client = Uploadcare::Client.new(
|
|
22
|
+
public_key: ENV.fetch('UPLOADCARE_PUBLIC_KEY'),
|
|
23
|
+
secret_key: ENV.fetch('UPLOADCARE_SECRET_KEY')
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
puts 'Starting upload...'
|
|
27
|
+
result = client.files.upload_from_url(url, store: true)
|
|
28
|
+
|
|
29
|
+
puts '✓ Upload successful!'
|
|
30
|
+
puts
|
|
31
|
+
puts "UUID: #{result.uuid}"
|
|
32
|
+
puts "Filename: #{result.original_filename}"
|
|
33
|
+
puts "Size: #{(result.size / 1024.0).round(2)} KB"
|
|
34
|
+
puts "MIME type: #{result.mime_type}"
|
|
35
|
+
puts
|
|
36
|
+
puts "CDN URL: #{result.cdn_url}"
|
|
37
|
+
puts
|
|
38
|
+
puts 'Advanced Usage:'
|
|
39
|
+
puts
|
|
40
|
+
puts '# Async mode (returns immediately with token):'
|
|
41
|
+
puts 'client = Uploadcare::Client.new(public_key: "...", secret_key: "...")'
|
|
42
|
+
puts "response = client.uploads.upload_from_url(url: '#{url}', async: true)"
|
|
43
|
+
puts "token = response['token']"
|
|
44
|
+
puts
|
|
45
|
+
puts '# Check status later:'
|
|
46
|
+
puts 'status = client.uploads.upload_from_url_status(token: token)'
|
|
47
|
+
puts "puts status['status']"
|
|
48
|
+
rescue StandardError => e
|
|
49
|
+
puts "✗ Upload failed: #{e.message}"
|
|
50
|
+
puts
|
|
51
|
+
puts 'Common issues:'
|
|
52
|
+
puts '- URL must be publicly accessible'
|
|
53
|
+
puts '- URL must return a valid file'
|
|
54
|
+
puts '- Some file types may not be supported'
|
|
55
|
+
exit 1
|
|
56
|
+
end
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# REST API endpoint for add-on operations.
|
|
4
|
+
#
|
|
5
|
+
# Supports AWS Rekognition (labels & moderation), ClamAV virus scan, and Remove.bg.
|
|
6
|
+
#
|
|
7
|
+
# @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/Add-Ons
|
|
8
|
+
class Uploadcare::Api::Rest::Addons
|
|
9
|
+
# @return [Uploadcare::Api::Rest] Parent REST client
|
|
10
|
+
attr_reader :rest
|
|
11
|
+
|
|
12
|
+
# @param rest [Uploadcare::Api::Rest] Parent REST client
|
|
13
|
+
def initialize(rest:)
|
|
14
|
+
@rest = rest
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Execute AWS Rekognition label detection.
|
|
18
|
+
#
|
|
19
|
+
# @param uuid [String] File UUID to process
|
|
20
|
+
# @param request_options [Hash] Request options
|
|
21
|
+
# @return [Uploadcare::Result] Hash with request_id
|
|
22
|
+
# @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/Add-Ons/operation/awsRekognitionExecute
|
|
23
|
+
def aws_rekognition_detect_labels(uuid:, request_options: {})
|
|
24
|
+
rest.post(path: '/addons/aws_rekognition_detect_labels/execute/',
|
|
25
|
+
params: { target: uuid }, headers: {}, request_options: request_options)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Check AWS Rekognition label detection status.
|
|
29
|
+
#
|
|
30
|
+
# @param request_id [String] Request ID from execution
|
|
31
|
+
# @param request_options [Hash] Request options
|
|
32
|
+
# @return [Uploadcare::Result] Hash with status
|
|
33
|
+
# @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/Add-Ons/operation/awsRekognitionExecutionStatus
|
|
34
|
+
def aws_rekognition_detect_labels_status(request_id:, request_options: {})
|
|
35
|
+
rest.get(path: '/addons/aws_rekognition_detect_labels/execute/status/',
|
|
36
|
+
params: { request_id: request_id }, headers: {}, request_options: request_options)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Execute AWS Rekognition moderation label detection.
|
|
40
|
+
#
|
|
41
|
+
# @param uuid [String] File UUID to process
|
|
42
|
+
# @param request_options [Hash] Request options
|
|
43
|
+
# @return [Uploadcare::Result] Hash with request_id
|
|
44
|
+
# @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/Add-Ons/operation/awsRekognitionDetectModerationLabelsExecute
|
|
45
|
+
def aws_rekognition_detect_moderation_labels(uuid:, request_options: {})
|
|
46
|
+
rest.post(path: '/addons/aws_rekognition_detect_moderation_labels/execute/',
|
|
47
|
+
params: { target: uuid }, headers: {}, request_options: request_options)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Check AWS Rekognition moderation label detection status.
|
|
51
|
+
#
|
|
52
|
+
# @param request_id [String] Request ID from execution
|
|
53
|
+
# @param request_options [Hash] Request options
|
|
54
|
+
# @return [Uploadcare::Result] Hash with status
|
|
55
|
+
# @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/Add-Ons/operation/awsRekognitionDetectModerationLabelsExecutionStatus
|
|
56
|
+
def aws_rekognition_detect_moderation_labels_status(request_id:, request_options: {})
|
|
57
|
+
rest.get(path: '/addons/aws_rekognition_detect_moderation_labels/execute/status/',
|
|
58
|
+
params: { request_id: request_id }, headers: {}, request_options: request_options)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Execute ClamAV virus scan.
|
|
62
|
+
#
|
|
63
|
+
# @param uuid [String] File UUID to process
|
|
64
|
+
# @param params [Hash] Optional scan parameters
|
|
65
|
+
# @param request_options [Hash] Request options
|
|
66
|
+
# @return [Uploadcare::Result] Hash with request_id
|
|
67
|
+
# @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/Add-Ons/operation/ucClamavVirusScanExecute
|
|
68
|
+
def uc_clamav_virus_scan(uuid:, params: {}, request_options: {})
|
|
69
|
+
body = { target: uuid }.merge(params)
|
|
70
|
+
rest.post(path: '/addons/uc_clamav_virus_scan/execute/', params: body, headers: {},
|
|
71
|
+
request_options: request_options)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# Check ClamAV virus scan status.
|
|
75
|
+
#
|
|
76
|
+
# @param request_id [String] Request ID from execution
|
|
77
|
+
# @param request_options [Hash] Request options
|
|
78
|
+
# @return [Uploadcare::Result] Hash with status
|
|
79
|
+
# @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/Add-Ons/operation/ucClamavVirusScanExecutionStatus
|
|
80
|
+
def uc_clamav_virus_scan_status(request_id:, request_options: {})
|
|
81
|
+
rest.get(path: '/addons/uc_clamav_virus_scan/execute/status/',
|
|
82
|
+
params: { request_id: request_id }, headers: {}, request_options: request_options)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# Execute Remove.bg background removal.
|
|
86
|
+
#
|
|
87
|
+
# @param uuid [String] File UUID to process
|
|
88
|
+
# @param params [Hash] Optional parameters for the add-on
|
|
89
|
+
# @param request_options [Hash] Request options
|
|
90
|
+
# @return [Uploadcare::Result] Hash with request_id
|
|
91
|
+
# @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/Add-Ons/operation/removeBgExecute
|
|
92
|
+
def remove_bg(uuid:, params: {}, request_options: {})
|
|
93
|
+
rest.post(path: '/addons/remove_bg/execute/',
|
|
94
|
+
params: { target: uuid, params: params }, headers: {}, request_options: request_options)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Check Remove.bg execution status.
|
|
98
|
+
#
|
|
99
|
+
# @param request_id [String] Request ID from execution
|
|
100
|
+
# @param request_options [Hash] Request options
|
|
101
|
+
# @return [Uploadcare::Result] Hash with status and result
|
|
102
|
+
# @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/Add-Ons/operation/removeBgExecutionStatus
|
|
103
|
+
def remove_bg_status(request_id:, request_options: {})
|
|
104
|
+
rest.get(path: '/addons/remove_bg/execute/status/',
|
|
105
|
+
params: { request_id: request_id }, headers: {}, request_options: request_options)
|
|
106
|
+
end
|
|
107
|
+
end
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# REST API endpoint for document conversion operations.
|
|
4
|
+
#
|
|
5
|
+
# @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/Conversion
|
|
6
|
+
class Uploadcare::Api::Rest::DocumentConversions
|
|
7
|
+
# @return [Uploadcare::Api::Rest] Parent REST client
|
|
8
|
+
attr_reader :rest
|
|
9
|
+
|
|
10
|
+
# @param rest [Uploadcare::Api::Rest] Parent REST client
|
|
11
|
+
def initialize(rest:)
|
|
12
|
+
@rest = rest
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Get document format information and possible conversion formats.
|
|
16
|
+
#
|
|
17
|
+
# @param uuid [String] Document file UUID
|
|
18
|
+
# @param request_options [Hash] Request options
|
|
19
|
+
# @return [Uploadcare::Result] Document format info
|
|
20
|
+
# @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/Conversion/operation/documentConvertInfo
|
|
21
|
+
def info(uuid:, request_options: {})
|
|
22
|
+
encoded_uuid = URI.encode_www_form_component(uuid.to_s)
|
|
23
|
+
rest.get(path: "/convert/document/#{encoded_uuid}/", params: {}, headers: {},
|
|
24
|
+
request_options: request_options)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Convert a document to a specified format.
|
|
28
|
+
#
|
|
29
|
+
# @param paths [Array<String>] Conversion paths (e.g., ["uuid/document/-/format/pdf/"])
|
|
30
|
+
# @param options [Hash] Optional parameters (:store, :save_in_group)
|
|
31
|
+
# @param request_options [Hash] Request options
|
|
32
|
+
# @return [Uploadcare::Result] Conversion details with result and problems
|
|
33
|
+
# @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/Conversion/operation/documentConvert
|
|
34
|
+
def convert(paths:, options: {}, request_options: {})
|
|
35
|
+
body = { paths: paths }
|
|
36
|
+
body[:store] = normalize_bool_param(options[:store]) if options.key?(:store)
|
|
37
|
+
body[:save_in_group] = normalize_bool_param(options[:save_in_group]) if options.key?(:save_in_group)
|
|
38
|
+
body.compact!
|
|
39
|
+
|
|
40
|
+
rest.post(path: '/convert/document/', params: body, headers: {}, request_options: request_options)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Get document conversion job status.
|
|
44
|
+
#
|
|
45
|
+
# @param token [String, Integer] Conversion job token
|
|
46
|
+
# @param request_options [Hash] Request options
|
|
47
|
+
# @return [Uploadcare::Result] Job status and result
|
|
48
|
+
# @see https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/Conversion/operation/documentConvertStatus
|
|
49
|
+
def status(token:, request_options: {})
|
|
50
|
+
rest.get(path: "/convert/document/status/#{token}/", params: {}, headers: {},
|
|
51
|
+
request_options: request_options)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
private
|
|
55
|
+
|
|
56
|
+
def normalize_bool_param(value)
|
|
57
|
+
normalized = value.is_a?(String) ? value.strip.downcase : value
|
|
58
|
+
|
|
59
|
+
case normalized
|
|
60
|
+
when true, 1, '1', 'true' then '1'
|
|
61
|
+
when false, 0, '0', 'false' then '0'
|
|
62
|
+
else value
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|