Skip to content

Commit aa09e3e

Browse files
committed
Polish v5 migration docs and wrapper return examples
1 parent cfe25e5 commit aa09e3e

File tree

2 files changed

+70
-37
lines changed

2 files changed

+70
-37
lines changed

MIGRATING_V5.md

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ This guide covers migration from `uploadcare-rails` 3.x/4.x to 5.0.
1010

1111
- Minimum supported Ruby is now `3.3+`.
1212

13+
### Rails version
14+
15+
- Minimum supported Rails is now `7.0+`.
16+
1317
### Dependency baseline
1418

1519
- `uploadcare-ruby` 5.x is now required.
@@ -47,6 +51,16 @@ Methods in `Uploadcare::*Api` wrappers now return `uploadcare-ruby` v5 objects/r
4751

4852
`Uploadcare::WebhookApi.delete_webhook` returns the direct SDK response payload.
4953

54+
### Wrapper object return contract
55+
56+
Mounted wrappers still work, but now return v5-native objects:
57+
58+
- `post.picture.store` -> `Uploadcare::Rails::File`
59+
- `post.picture.delete` -> `Uploadcare::File`
60+
- `post.picture.load` -> `Uploadcare::Rails::File`
61+
- `post.attachments.store` -> `Uploadcare::Group`
62+
- `post.attachments.load` -> `Uploadcare::Rails::Group`
63+
5064
### Conversion API return contract
5165

5266
`Uploadcare::ConversionApi` no longer uses `dry-monads` style `Success(...)`/`Failure(...)` wrappers.
@@ -58,11 +72,41 @@ It now returns direct v5 SDK values:
5872
- `get_document_conversion_status` -> `Uploadcare::DocumentConverter`
5973
- `get_document_conversion_formats_info` -> `Uploadcare::DocumentConverter`
6074

75+
## New in 5.0
76+
77+
### Per-model Uploadcare config selection
78+
79+
`mount_uploadcare_file` and `mount_uploadcare_file_group` now accept `uploadcare_config:`.
80+
You can pass either an `Uploadcare::Configuration` instance or a proc.
81+
82+
```ruby
83+
class Post < ApplicationRecord
84+
mount_uploadcare_file :picture, uploadcare_config: -> {
85+
Uploadcare::Rails.client_config(
86+
public_key: tenant_uploadcare_public_key,
87+
secret_key: tenant_uploadcare_secret_key
88+
)
89+
}
90+
end
91+
```
92+
93+
When async store/delete jobs are enabled, this configuration is serialized and passed into jobs automatically.
94+
95+
### Active Storage integration
96+
97+
`ActiveStorage::Service::UploadcareService` is available in `5.0`.
98+
99+
Current limitation:
100+
101+
- Direct upload URL flow is not implemented yet (`url_for_direct_upload` raises `NotImplementedError`).
102+
61103
## Migration checklist
62104

63105
1. Upgrade Ruby to `3.3+`.
64-
2. Upgrade to `uploadcare-rails` 5.x.
65-
3. Replace any `Uploadcare.config` usage with `Uploadcare.configuration`.
66-
4. Update integrations that expected Hash/monad responses from wrapper APIs.
67-
5. Run your full application and test suite.
68-
106+
2. Upgrade Rails to `7.0+`.
107+
3. Upgrade to `uploadcare-rails` 5.x.
108+
4. Replace any `Uploadcare.config` usage with `Uploadcare.configuration`.
109+
5. Update integrations that expected Hash/monad responses from wrapper APIs.
110+
6. If you use per-tenant keys, move mounts/API calls to explicit `uploadcare_config:` / `config:` usage.
111+
7. If you use Active Storage direct upload flow, keep your existing service until this is implemented.
112+
8. Run your full application and test suite.

README.md

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,19 @@ class Post < ApplicationRecord
247247
end
248248
```
249249

250+
For multi-tenant setups, you can bind a non-default Uploadcare config:
251+
252+
```ruby
253+
class Post < ApplicationRecord
254+
mount_uploadcare_file :picture, uploadcare_config: -> {
255+
Uploadcare::Rails.client_config(
256+
public_key: tenant_uploadcare_public_key,
257+
secret_key: tenant_uploadcare_secret_key
258+
)
259+
}
260+
end
261+
```
262+
250263
```erb
251264
<!-- app/views/posts/new.html.erb -->
252265
<h1> NEW POST </h1>
@@ -272,6 +285,8 @@ class Post < ApplicationRecord
272285
end
273286
```
274287

288+
`mount_uploadcare_file_group` also supports `uploadcare_config:` in the same way.
289+
275290
```erb
276291
<!-- app/views/posts/new.html.erb -->
277292
<h1> NEW POST </h1>
@@ -372,18 +387,12 @@ Now the `post.picture` is an Uploadcare::Rails::File. Following methods are supp
372387
```ruby
373388
# Store the file on an Uploadcare server permanently:
374389
post.picture.store
375-
# => {
376-
# "cdn_url"=>"https://ucarecdn.com/2d33999d-c74a-4ff9-99ea-abc23496b052/",
377-
# ...other group data...
378-
# }
390+
# => #<Uploadcare::Rails::File ...>
379391

380392
#
381393
# Delete the file from an Uploadcare server permanently:
382394
post.picture.delete
383-
# => {
384-
# "datetime_removed"=>"2021-07-30T09:19:30.797174Z",
385-
# ...other group data...
386-
# }
395+
# => #<Uploadcare::File ...>
387396

388397
# Get CDN-url of an object attribute:
389398
post.picture.to_s
@@ -393,10 +402,7 @@ post.picture.to_s
393402
# This data will be cached if the cache_files option is set to true
394403
# Default data (without asking an Uploadcare server) for each file contains cdn_url and uuid only:
395404
post.picture.load
396-
# => {
397-
# "cdn_url"=>"https://ucarecdn.com/2d33999d-c74a-4ff9-99ea-abc23496b052/",
398-
# ...other file data...
399-
# }
405+
# => #<Uploadcare::Rails::File ...>
400406

401407
# Check if an attribute loaded from the server.
402408
# Will return false unless the :load or the :store methods are called:
@@ -431,37 +437,20 @@ Now the `post.attachments` is an Uploadcare::Rails::Group. Following methods are
431437
```ruby
432438
# Store the file group on an Uploadcare server permanently:
433439
post.attachments.store
434-
# => {
435-
# "cdn_url"=>"https://ucarecdn.com/dbc4e868-b7a6-43ff-a35f-2ebef935dc1b~1/",
436-
# ...other group data...
437-
# "files"=> [{
438-
# "datetime_stored"=>"2021-07-29T08:31:45.668354Z",
439-
# ...other file data...
440-
# }]
441-
# }
440+
# => #<Uploadcare::Group ...>
442441

443442
#
444443
# Delete the file group from an Uploadcare server permanently:
445444
post.attachments.delete
446-
# => {
447-
# "datetime_removed"=>"2021-07-30T09:19:30.797174Z",
448-
# ...other group data...
449-
# }
445+
# => #<direct SDK response payload>
450446

451447
# Get CDN-url of an object attribute:
452448
post.attachments.to_s
453449
# => "https://ucarecdn.com/dbc4e868-b7a6-43ff-a35f-2ebef935dc1b~1/"
454450

455451
# Load object — works the same way as for the File:
456452
post.attachments.load
457-
# => {
458-
# "cdn_url"=>"https://ucarecdn.com/dbc4e868-b7a6-43ff-a35f-2ebef935dc1b~1/",
459-
# ...other group data...
460-
# "files"=> [{
461-
# "datetime_stored"=>"2021-07-29T08:31:45.668354Z",
462-
# ...other file data...
463-
# }]
464-
# }
453+
# => #<Uploadcare::Rails::Group ...>
465454

466455
# Check if an attribute loaded from the server:
467456
post.attachments.loaded?

0 commit comments

Comments
 (0)