Ruby API Client
Ruby integration handles uploads and file operations by wrapping Uploadcare Upload API and REST API. This comprehensive API client lets you use most of the Uploadcare features from within your Ruby app.
Features
Uploading (Upload API):
- Upload files from local storage and URLs (up to 5 TB)
- Multipart uploading for large files
- Uploading network to speed uploading jobs (like CDN)
File management (REST API):
- Get file info and perform various operations (store/delete) with them
- Work with groups of files
- Get info about account project
- Manage webhooks
- Convert documents
- Encode and transform videos
Image processing (URL API):
- Compression
- Geometry
- Colors
- Definition
- Image and text overlays
- Rotations
- Recognition
- File info
- Proxy (fetch)
Security features:
- Secure authentication
- Secure uploads (signed uploads)
- Secure delivery (signed URLs)
- Secure webhooks (signing secret)
Requirements
- Ruby 3.3+
Upgrading from v4.x? See the migration guide.
Install
Add this line to your application’s Gemfile:
And then execute:
If already not, create your project in Uploadcare dashboard and copy your API keys from there.
Set your Uploadcare keys in config file or through environment variables:
Or configure your app yourself if you are using different way of storing keys.
Gem configuration is available in Uploadcare.configuration. Full list of
settings can be seen in lib/uploadcare.rb
Examples
Quick start
Upload API
Upload from URL
View full script: post_from_url.rb
Multipart upload (large files)
View related scripts: post_multipart_start.rb, post_multipart_complete.rb
REST API
Get file info
View full script: get_files_uuid.rb
Add a webhook
View full script: post_webhooks.rb
Note: All examples assume you configured your API keys. Replace placeholders with your actual keys, or set them via environment variables.
Uploading and storing a single file
Using Uploadcare is simple, and here are the basics of handling files.
You might then want to store or delete the uploaded file. Storing files could be crucial if you aren’t using the “Automatic file storing” option for your Uploadcare project. If not stored manually or automatically, files get deleted within a 24-hour period.
More upload methods
Uploadcare supports multiple ways to upload files:
Upload options
You can override global :autostore option for each upload request:
Client
Most methods are available through a Uploadcare::Client instance:
Entity object
Entities are representations of objects in Uploadcare cloud.
File
File entity contains its metadata.
Note:
content_inforeplaces the oldimage_infofield and covers image dimensions, video duration/bitrate, and audio info.
Note:
copyis no longer available. Usecopy_to_localorcopy_to_remoteinstead.
Metadata of deleted files is stored permanently.
FileList
FileList represents the whole collection of files (or a subset) and provides a way to iterate through it, making pagination transparent.
FileList objects can be created using client.files.list.
Full documentation
Read the full documentation on GitHub.