uploadcare-rails 3.3.2 → 3.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +178 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +21 -0
- data/README.md +971 -0
- data/lib/uploadcare/rails/version.rb +1 -1
- data/uploadcare-rails.gemspec +54 -0
- metadata +21 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4730dfdd1bbeee9718fa09b3b3ac30ede4ae7e67fbbd2cbc11523d9d9592251
|
4
|
+
data.tar.gz: 508408a40d0506c56bda9979ec95aab8b689b9af9dfad170dcfe5099786b6994
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e39ed85580c904e02ec0c5bf62611224de9f55aeb3b6d9a802d78df88bf93c414c27942c9aa812b1c34ac3a765412322f4bb14a93d568d699c6fc89570339f0
|
7
|
+
data.tar.gz: 05a91828bd6b02416009a52c2ea2b63dea78f2ab7ea3b4002ac4c44f69c2f0922d1de1ae503d946dad8611a9966ea4e886b7813dd057ff850bcf42185b5fbfd0
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,178 @@
|
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
The format is based now on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
5
|
+
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
6
|
+
|
7
|
+
## 3.3.3 — 2023-03-27
|
8
|
+
|
9
|
+
### Changed
|
10
|
+
|
11
|
+
* Improved readme to look better at ruby-doc
|
12
|
+
|
13
|
+
## 3.3.2.1 — 2023-03-26
|
14
|
+
|
15
|
+
### Changed
|
16
|
+
|
17
|
+
* Updated links in the gemspec
|
18
|
+
|
19
|
+
## 3.3.2 — 2023-03-26
|
20
|
+
|
21
|
+
### Changed
|
22
|
+
|
23
|
+
* Fixed an issue with the configuration
|
24
|
+
* Updated the gem documentation
|
25
|
+
|
26
|
+
## 3.3.1 — 2023-03-20
|
27
|
+
|
28
|
+
### Changed
|
29
|
+
|
30
|
+
* Updated gem description
|
31
|
+
* Respect data-multiple in helper options (https://github.com/uploadcare/uploadcare-rails/issues/119)
|
32
|
+
|
33
|
+
## 3.3.0 — 2023-03-16
|
34
|
+
|
35
|
+
Guarantee support of maintainable versions of Ruby and Rails.
|
36
|
+
|
37
|
+
### Breaking Сhanges
|
38
|
+
|
39
|
+
Drop support of unmaintainable Ruby 2.4, 2.5, 2.6 and Rails before 6.0.
|
40
|
+
|
41
|
+
### Added
|
42
|
+
|
43
|
+
Add support of Ruby 3.1 and 3.2 and Rails 7.0.
|
44
|
+
|
45
|
+
## 3.0.0 — 2022-12-29
|
46
|
+
|
47
|
+
This version supports latest Uploadcare REST API — [v0.7](https://uploadcare.com/api-refs/rest-api/v0.7.0/), which introduces new file management features:
|
48
|
+
* [File metadata](https://uploadcare.com/docs/file-metadata/)
|
49
|
+
* New [add-ons API](https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/Add-Ons):
|
50
|
+
* [Background removal](https://uploadcare.com/docs/remove-bg/)
|
51
|
+
* [Virus checking](https://uploadcare.com/docs/security/malware-protection/)
|
52
|
+
* [Object recognition](https://uploadcare.com/docs/intelligence/object-recognition/)
|
53
|
+
|
54
|
+
### Breaking Сhanges
|
55
|
+
|
56
|
+
- For `Uploadcare::FileApi#get_file`
|
57
|
+
- File information doesn't return `image_info` and `video_info` fields anymore
|
58
|
+
- Removed `rekognition_info` in favor of `appdata`
|
59
|
+
- Parameter `add_fields` was renamed to `include`
|
60
|
+
- For `Uploadcare::FileApi#get_files`
|
61
|
+
- Removed the option of sorting the file list by file size
|
62
|
+
- For `Uploadcare::GroupApi#store_group`
|
63
|
+
- Changed response format
|
64
|
+
- For `Uploadcare::FileApi`
|
65
|
+
- Removed method `copy_file` in favor of `local_copy_file` and `remote_copy_file` methods
|
66
|
+
|
67
|
+
### Changed
|
68
|
+
|
69
|
+
- For `Uploadcare::FileApi#get_file`
|
70
|
+
- Field `content_info` that includes mime-type, image (dimensions, format, etc), video information (duration, format, bitrate, etc), audio information, etc
|
71
|
+
- Field `metadata` that includes arbitrary metadata associated with a file
|
72
|
+
- Field `appdata` that includes dictionary of application names and data associated with these applications
|
73
|
+
|
74
|
+
### Added
|
75
|
+
|
76
|
+
- Add Uploadcare API interface:
|
77
|
+
- `Uploadcare::FileMetadataApi`
|
78
|
+
- `Uploadcare::AddonsApi`
|
79
|
+
- Added an option to delete a Group
|
80
|
+
- For `Uploadcare::FileApi` add `local_copy_file` and `remote_copy_file` methods
|
81
|
+
|
82
|
+
## 2.1.1 2022-05-13
|
83
|
+
### Fix
|
84
|
+
|
85
|
+
Fixed Rails 4 tests by enforcing https.
|
86
|
+
|
87
|
+
## 2.1.0 2021-11-16
|
88
|
+
### Added
|
89
|
+
|
90
|
+
- Option `signing_secret` in the `Uploadcare::WebhookApi`.
|
91
|
+
|
92
|
+
## 2.0.0 - 2021-10-11
|
93
|
+
### :heavy_exclamation_mark: *Note: the gem uploadcare-rails 2.x is not backward compatible with 1.x.*
|
94
|
+
|
95
|
+
### Added
|
96
|
+
|
97
|
+
- Add Uploadcare API interface:
|
98
|
+
- Uploadcare::FileApi
|
99
|
+
- Uploadcare::UploadApi
|
100
|
+
- Uploadcare::GroupApi
|
101
|
+
- Uploadcare::ConversionApi
|
102
|
+
- Uploadcare::ProjectApi
|
103
|
+
- Uploadcare::WebhookApi
|
104
|
+
- Add uploadcare_widget_tag helper for views
|
105
|
+
- Add methods File#store, File#delete, File#load
|
106
|
+
- Add methods Group#transform_file_urls, Group#store, Group#load
|
107
|
+
|
108
|
+
### Changed
|
109
|
+
|
110
|
+
- Change File Uploader widget view helpers
|
111
|
+
- Rename has_uploadcare_file -> mount_uploadcare_file
|
112
|
+
- Rename has_uploadcare_group -> mount_uploadcare_file_group
|
113
|
+
- Change generated config path from config/uploadcare.yml to config/initializers/uploadcare.rb and add more options
|
114
|
+
- Rename the class `Uploadcare::Rails::Settings` to `Uploadcare::Rails::Configuration`
|
115
|
+
- Rename the class `Uploadcare::Rails::Operations` to `Uploadcare::Rails::Transformations::ImageTransformations`.
|
116
|
+
Configuration object is available as `Uploadcare::Rails.configuration` now
|
117
|
+
- Change methods File#url -> File#transform_url
|
118
|
+
- Change methods Group#urls -> Group#file_urls
|
119
|
+
- Change methods Group#load_data -> Group#load
|
120
|
+
|
121
|
+
### Removed
|
122
|
+
|
123
|
+
- Remove uploadcare_uploader_tag helper
|
124
|
+
- Remove uploadcare_multiple_uploader_field helper
|
125
|
+
- Remove uploadcare_single_uploader_field helper
|
126
|
+
- Remove uploadcare_uploader_options (now options are included in uploadcare_widget_tag)
|
127
|
+
- Remove FormBuilder support
|
128
|
+
- Remove Formtastic support
|
129
|
+
- Remove SimpleForm support
|
130
|
+
- Remove caching files and groups on delete
|
131
|
+
- Remove callback ```ruby after_save after_save "store_#{ attribute }".to_sym```. Now managed by the `do_not_store` option in `config/initializers/uploadcare.rb`
|
132
|
+
- Remove methods File#prepared_operations, File#to_builder, File#to_json, File#as_json, File#marshal_dump, File#image
|
133
|
+
- Remove methods Group#cache_data, Group#to_json, Group#as_json, Group#map_files, Group#load_data!, Group#marshal_dump
|
134
|
+
|
135
|
+
## 1.2.1 - 2018-10-01
|
136
|
+
### Fixed
|
137
|
+
- Allow to use multiple files or groups
|
138
|
+
|
139
|
+
## 1.2.0 - 2018-06-03
|
140
|
+
|
141
|
+
## 1.2.0-alpha3 - 2018-05-29
|
142
|
+
### Fixed
|
143
|
+
|
144
|
+
- Require `uploadcare/rails/version` in `lib/uploadcare-rails.rb`
|
145
|
+
|
146
|
+
## 1.2.0-alpha2 - 2018-05-28 - YANKED
|
147
|
+
### Changed
|
148
|
+
- Gem now reports us your `uploadcare-rails` and `rails` versions using the User-Agent header (overridable via config)
|
149
|
+
- `uploadcare-ruby` gem version bumped to 1.2.x
|
150
|
+
|
151
|
+
|
152
|
+
## 1.2.0-alpha - 2018-04-18
|
153
|
+
### Changed
|
154
|
+
- Allow gem in rails 5.2
|
155
|
+
- Update default widget version to 3.x
|
156
|
+
|
157
|
+
### Removed
|
158
|
+
- Tests against Ruby 2.0 and 2.1 that [had reached their EOL](https://www.ruby-lang.org/en/downloads/branches/)
|
159
|
+
|
160
|
+
|
161
|
+
## 1.1.1 - 2017-11-07
|
162
|
+
### Fixed
|
163
|
+
- Uploadcare config generator
|
164
|
+
- Issues preventing the gem to be used with rails 5.1
|
165
|
+
|
166
|
+
|
167
|
+
## 1.1.0 - 2016-07-12
|
168
|
+
### Added
|
169
|
+
- Removed widget from the asset pipeline. It is expected to use helper or to append to the asset pipeline manually.
|
170
|
+
- Operations for image_tag helpers.
|
171
|
+
|
172
|
+
### Fixed
|
173
|
+
- Bug with creating object with empty file or file_group.
|
174
|
+
- Workaround to remove unnecessary API-calls for groups of images.
|
175
|
+
|
176
|
+
### Development
|
177
|
+
- Tests have been refactored, VCR appended to development environment.
|
178
|
+
- Tests performance improvements.
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 dmitrij
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,971 @@
|
|
1
|
+
# Uploadcare Rails
|
2
|
+
|
3
|
+
![license](https://img.shields.io/badge/license-MIT-brightgreen.svg)
|
4
|
+
[![Build Status][actions-img]][actions-badge]
|
5
|
+
|
6
|
+
[actions-badge]: https://github.com/uploadcare/uploadcare-rails/actions/workflows/test.yml
|
7
|
+
[actions-img]: https://github.com/uploadcare/uploadcare-rails/actions/workflows/test.yml/badge.svg
|
8
|
+
|
9
|
+
A Ruby on Rails plugin for [Uploadcare](https://uploadcare.com) service.
|
10
|
+
Based on [uploadcare-ruby](https://github.com/uploadcare/uploadcare-ruby) gem (general purpose wrapper for Uploadcare API)
|
11
|
+
|
12
|
+
:heavy_exclamation_mark: *Note: the gem uploadcare-rails 2.x is not backward compatible with 1.x.*
|
13
|
+
|
14
|
+
## Table of Contents
|
15
|
+
|
16
|
+
* [Requirements](#requirements)
|
17
|
+
* [Installation](#installation)
|
18
|
+
* [Using Gemfile](#using-gemfile)
|
19
|
+
* [Using command line](#using-command-line)
|
20
|
+
* [Usage](#usage)
|
21
|
+
* [Configuration](#configuration)
|
22
|
+
* [Uploadcare File Uploader](#uploadcare-file-uploader)
|
23
|
+
* [Widget](#widget)
|
24
|
+
* [Using CDN](#using-cdn)
|
25
|
+
* [Using NPM](#using-npm)
|
26
|
+
* [Input](#input)
|
27
|
+
* [Using the File Uploader with Rails models](#using-the-file-uploader-with-rails-models)
|
28
|
+
* [Form data](#form-data)
|
29
|
+
* [File and Group wrappers](#file-and-group-wrappers)
|
30
|
+
* [Image Transformation](#image-transformation)
|
31
|
+
* [Uploadcare API interfaces](#uploadcare-api-interfaces)
|
32
|
+
* [Upload Api](#upload-api)
|
33
|
+
* [File Api](#file-api)
|
34
|
+
* [Group Api](#group-api)
|
35
|
+
* [Project Api](#project-api)
|
36
|
+
* [Webhook Api](#webhook-api)
|
37
|
+
* [Conversion Api](#conversion-api)
|
38
|
+
* [File Metadata Api](#file-metadata-api)
|
39
|
+
* [Add-Ons Api](#add-ons-api)
|
40
|
+
* [Useful links](#useful-links)
|
41
|
+
|
42
|
+
## Requirements
|
43
|
+
* ruby 2.7+
|
44
|
+
* Ruby on Rails 6.0+
|
45
|
+
|
46
|
+
## Installation
|
47
|
+
|
48
|
+
### Using Gemfile
|
49
|
+
|
50
|
+
Add this line to your application's Gemfile:
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
gem "uploadcare-rails"
|
54
|
+
```
|
55
|
+
|
56
|
+
And then execute:
|
57
|
+
|
58
|
+
```console
|
59
|
+
$ bundle install
|
60
|
+
```
|
61
|
+
|
62
|
+
If you use `api_struct` gem in your project, replace it with `uploadcare-api_struct`:
|
63
|
+
```ruby
|
64
|
+
gem 'uploadcare-api_struct'
|
65
|
+
```
|
66
|
+
and run `bundle install`
|
67
|
+
|
68
|
+
### Using command line
|
69
|
+
|
70
|
+
```console
|
71
|
+
$ gem install uploadcare-rails
|
72
|
+
```
|
73
|
+
|
74
|
+
## Usage
|
75
|
+
|
76
|
+
### Configuration
|
77
|
+
|
78
|
+
To start using Uploadcare API you just need to set your [API keys](https://app.uploadcare.com/projects/-/api-keys/) (public key and secret key).
|
79
|
+
These keys can be set as ENV variables using the `export` directive:
|
80
|
+
|
81
|
+
```console
|
82
|
+
$ export UPLOADCARE_PUBLIC_KEY=your_public_key
|
83
|
+
$ export UPLOADCARE_SECRET_KEY=your_private_key
|
84
|
+
```
|
85
|
+
Or you can use popular gems like `dotenv-rails` for setting ENV variables.
|
86
|
+
You must set the gem before `uploadcare-rails` like this :
|
87
|
+
```ruby
|
88
|
+
gem "dotenv-rails", require: "dotenv/rails-now", groups: [:development, :test]
|
89
|
+
gem "uploadcare-rails"
|
90
|
+
```
|
91
|
+
:warning: `require: "dotenv/rails-now"` is very important!
|
92
|
+
|
93
|
+
Run the config generator command to generate a configuration file:
|
94
|
+
|
95
|
+
```console
|
96
|
+
$ rails g uploadcare_config
|
97
|
+
```
|
98
|
+
|
99
|
+
The generator will create a new file in `config/initializers/uploadcare.rb`.
|
100
|
+
|
101
|
+
The public key must be specified in `config/initializers/uploadcare.rb` to use Uploadcare file upload.
|
102
|
+
This step is done automatically in the initializer if you set the ENV variable `UPLOADCARE_PUBLIC_KEY` earlier.
|
103
|
+
|
104
|
+
```ruby
|
105
|
+
...
|
106
|
+
Uploadcare::Rails.configure do |config|
|
107
|
+
# Sets your Uploadcare public key.
|
108
|
+
config.public_key = ENV.fetch("UPLOADCARE_PUBLIC_KEY", "your_public_key")
|
109
|
+
...
|
110
|
+
end
|
111
|
+
```
|
112
|
+
|
113
|
+
There are also some options set by default:
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
...
|
117
|
+
# Deletes files from Uploadcare servers after object destroy.
|
118
|
+
config.delete_files_after_destroy = true
|
119
|
+
|
120
|
+
# Sets caching for Uploadcare files
|
121
|
+
config.cache_files = true
|
122
|
+
|
123
|
+
# Available locales currently are:
|
124
|
+
# ar az ca cs da de el en es et fr he it ja ko lv nb nl pl pt ro ru sk sr sv tr uk vi zhTW zh
|
125
|
+
config.locale = "en"
|
126
|
+
|
127
|
+
# If true, inputs on your page are initialized automatically, see the article for details -
|
128
|
+
# https://uploadcare.com/docs/file-uploader-api/widget-initialization/
|
129
|
+
config.live = true
|
130
|
+
|
131
|
+
# If true, input initialization is invoked manually.
|
132
|
+
# See https://uploadcare.com/docs/file-uploader-api/widget-initialization/).
|
133
|
+
config.manual_start = false
|
134
|
+
```
|
135
|
+
|
136
|
+
Then you can configure all global variables such as files storing/caching, deleting files, etc.
|
137
|
+
Full list of available options is listed in the file itself. Just uncomment an option and set the value.
|
138
|
+
|
139
|
+
|
140
|
+
### Uploadcare File Uploader
|
141
|
+
|
142
|
+
### Widget
|
143
|
+
|
144
|
+
#### Using CDN
|
145
|
+
|
146
|
+
The fastest way to start using file uploading is to add the Uploadcare widget to the html-page.
|
147
|
+
There is a view helper that can do it with two strings of code:
|
148
|
+
|
149
|
+
Add this string to your `<head>` html-tag
|
150
|
+
|
151
|
+
```erb
|
152
|
+
<!DOCTYPE html>
|
153
|
+
<html>
|
154
|
+
<head>
|
155
|
+
<title>RailsApp</title>
|
156
|
+
<%= uploadcare_widget_tag %>
|
157
|
+
<!--
|
158
|
+
results in:
|
159
|
+
<script src="https://ucarecdn.com/libs/widget/3.x/uploadcare.full.min.js"></script>
|
160
|
+
<script>
|
161
|
+
//<![CDATA[
|
162
|
+
UPLOADCARE_PUBLIC_KEY = "your_public_key";
|
163
|
+
UPLOADCARE_LOCALE = "en";
|
164
|
+
UPLOADCARE_LIVE = true;
|
165
|
+
UPLOADCARE_MANUAL_START = false;
|
166
|
+
//]]>
|
167
|
+
</script>
|
168
|
+
-->
|
169
|
+
</head>
|
170
|
+
...
|
171
|
+
```
|
172
|
+
This helper uses a CDN-url for the widget bundle and supports three options:
|
173
|
+
|
174
|
+
- **version** — version of the Uploadcare widget. Default is "3.x".
|
175
|
+
- **bundle** — bundle name. Available names are "full", "default", "api", "ie8" and "lang.en".
|
176
|
+
Default bundle is "full" — a full bundle with built-in jQuery.
|
177
|
+
More info about bundles [here](https://uploadcare.com/docs/uploads/file-uploader/#bundles).
|
178
|
+
- **min** — bool value detecting if the bundle must be minified.
|
179
|
+
|
180
|
+
The `<head>` tag then also includes the `<script>` with widget global settings set in `config/initializers/uploadcare.rb`. You can override them later in an individual widget.
|
181
|
+
|
182
|
+
|
183
|
+
#### Using asset pipeline.
|
184
|
+
|
185
|
+
Download and append widget manually to your asset pipeline. You may download (e.g. https://ucarecdn.com/libs/widget/3.x/uploadcare.full.min.js) and serve the widget yourself along with your other assets.
|
186
|
+
|
187
|
+
#### Using NPM
|
188
|
+
|
189
|
+
Installing via NPM instructions can be found [here](https://uploadcare.com/docs/uploads/file-uploader/#npm).
|
190
|
+
|
191
|
+
### Input
|
192
|
+
|
193
|
+
When the widget is on a html-page, you want to add an input to your view that will be used by the File Uploader:
|
194
|
+
|
195
|
+
```erb
|
196
|
+
...
|
197
|
+
<%= uploadcare_uploader_field :object, :attribute %>
|
198
|
+
<!--
|
199
|
+
results in:
|
200
|
+
<input role="uploadcare-uploader" type="hidden" name="object[attribute]" id="object_attribute">
|
201
|
+
-->
|
202
|
+
...
|
203
|
+
```
|
204
|
+
|
205
|
+
- **object** — object name;
|
206
|
+
- **attribute** — object attribute name.
|
207
|
+
|
208
|
+
### Using the File Uploader with Rails models
|
209
|
+
|
210
|
+
View helpers are good to be used for Rails models.
|
211
|
+
First, you need to mount uploadcare file or group to the model attribute.
|
212
|
+
For example you have a database table like this and model `Post`:
|
213
|
+
```
|
214
|
+
# DB table "posts"
|
215
|
+
---------------------
|
216
|
+
title | String
|
217
|
+
---------------------
|
218
|
+
picture | String
|
219
|
+
---------------------
|
220
|
+
attachments | String
|
221
|
+
---------------------
|
222
|
+
```
|
223
|
+
|
224
|
+
### Form data
|
225
|
+
|
226
|
+
#### Uploadcare File
|
227
|
+
|
228
|
+
```ruby
|
229
|
+
# app/models/post.rb
|
230
|
+
class Post < ApplicationRecord
|
231
|
+
mount_uploadcare_file :picture
|
232
|
+
end
|
233
|
+
```
|
234
|
+
|
235
|
+
```erb
|
236
|
+
<!-- app/views/posts/new.html.erb -->
|
237
|
+
<h1> NEW POST </h1>
|
238
|
+
|
239
|
+
<%= form_tag("/posts", method: :post) do %>
|
240
|
+
<%= uploadcare_uploader_field :post, :picture %>
|
241
|
+
<!--
|
242
|
+
results in:
|
243
|
+
<input role="uploadcare-uploader" multiple="false" type="hidden" name="post[picture]" id="post_picture">
|
244
|
+
-->
|
245
|
+
<div>
|
246
|
+
<%= submit_tag "Save" %>
|
247
|
+
</div>
|
248
|
+
<% end %>
|
249
|
+
```
|
250
|
+
|
251
|
+
#### Uploadcare File Group
|
252
|
+
|
253
|
+
```ruby
|
254
|
+
# app/models/post.rb
|
255
|
+
class Post < ApplicationRecord
|
256
|
+
mount_uploadcare_file_group :attachments
|
257
|
+
end
|
258
|
+
```
|
259
|
+
|
260
|
+
```erb
|
261
|
+
<!-- app/views/posts/new.html.erb -->
|
262
|
+
<h1> NEW POST </h1>
|
263
|
+
|
264
|
+
<%= form_tag("/posts", method: :post) do %>
|
265
|
+
<%= uploadcare_uploader_field :post, :attachments %>
|
266
|
+
<!--
|
267
|
+
results in:
|
268
|
+
<input role="uploadcare-uploader" multiple="true" type="hidden" name="post[attachments]" id="post_attachments">
|
269
|
+
-->
|
270
|
+
<div>
|
271
|
+
<%= submit_tag "Save" %>
|
272
|
+
</div>
|
273
|
+
<% end %>
|
274
|
+
```
|
275
|
+
|
276
|
+
The input will have a `value` property set to CDN-urls when you will select files to upload in the widget.
|
277
|
+
|
278
|
+
```erb
|
279
|
+
<input role="uploadcare-uploader" type="hidden" name="post[picture]" id="post_picture" value="https://ucarecdn.com/8355c2c5-f108-4d74-963d-703d48020f83/">
|
280
|
+
```
|
281
|
+
|
282
|
+
So, you get CDN-urls as a value of the attribute in the controller on form submit.
|
283
|
+
The value will be available in the controller by `params[:post][:picture]`.
|
284
|
+
|
285
|
+
The helper is detecting the value of the `multiple` property based on the mount type in your model.
|
286
|
+
|
287
|
+
### File and Group wrappers
|
288
|
+
|
289
|
+
When you mount either Uploadcare File or Group to an attribute, this attribute is getting wrapped with
|
290
|
+
a Uploadcare object. This feature adds some usefull methods to the attribute.
|
291
|
+
|
292
|
+
#### Uploadcare File
|
293
|
+
|
294
|
+
Say, you have such model in your Rails app:
|
295
|
+
|
296
|
+
```ruby
|
297
|
+
# app/models/post.rb
|
298
|
+
class Post < ApplicationRecord
|
299
|
+
mount_uploadcare_file :picture
|
300
|
+
end
|
301
|
+
```
|
302
|
+
|
303
|
+
And then you create a new Post object specifying a CDN-url for your prevously uploaded Uploadcare file:
|
304
|
+
|
305
|
+
```console
|
306
|
+
$ post = Post.create(picture: "https://ucarecdn.com/2d33999d-c74a-4ff9-99ea-abc23496b052/")
|
307
|
+
```
|
308
|
+
|
309
|
+
Now the `post.picture` is an Uploadcare::Rails::File. Following methods are supported:
|
310
|
+
|
311
|
+
```console
|
312
|
+
# Store the file on an Uploadcare server permanently:
|
313
|
+
$ post.picture.store
|
314
|
+
# => {
|
315
|
+
# "cdn_url"=>"https://ucarecdn.com/2d33999d-c74a-4ff9-99ea-abc23496b052/",
|
316
|
+
# ...other group data...
|
317
|
+
# }
|
318
|
+
#
|
319
|
+
# Delete the file from an Uploadcare server permanently:
|
320
|
+
$ post.picture.delete
|
321
|
+
# => {
|
322
|
+
# "datetime_removed"=>"2021-07-30T09:19:30.797174Z",
|
323
|
+
# ...other group data...
|
324
|
+
# }
|
325
|
+
#
|
326
|
+
# Get CDN-url of an object attribute:
|
327
|
+
$ post.picture.to_s
|
328
|
+
# => "https://ucarecdn.com/2d33999d-c74a-4ff9-99ea-abc23496b052/"
|
329
|
+
#
|
330
|
+
# Load object (send a GET request to the server to get all the file's data)
|
331
|
+
# This data will be cached if the cache_files option is set to true
|
332
|
+
# Default data (without asking an Uploadcare server) for each file contains cdn_url and uuid only:
|
333
|
+
$ post.picture.load
|
334
|
+
# => {
|
335
|
+
# "cdn_url"=>"https://ucarecdn.com/2d33999d-c74a-4ff9-99ea-abc23496b052/",
|
336
|
+
# ...other file data...
|
337
|
+
# }
|
338
|
+
#
|
339
|
+
# Check if an attribute loaded from the server.
|
340
|
+
# Will return false unless the :load or the :store methods are called:
|
341
|
+
$ post.picture.loaded?
|
342
|
+
# => true
|
343
|
+
#
|
344
|
+
# More about image transformations below.
|
345
|
+
# Transform a CDN-url to get a new transformed image's source. Works for images only:
|
346
|
+
$ post.picture.transform_url(quality: "better")
|
347
|
+
# => "https://ucarecdn.com/2d33999d-c74a-4ff9-99ea-abc23496b052/-/quality/better/"
|
348
|
+
```
|
349
|
+
|
350
|
+
#### Uploadcare File Group
|
351
|
+
|
352
|
+
Groups work similar to the File but have some differences though.
|
353
|
+
|
354
|
+
```ruby
|
355
|
+
# app/models/post.rb
|
356
|
+
class Post < ApplicationRecord
|
357
|
+
mount_uploadcare_file_group :attachments
|
358
|
+
end
|
359
|
+
```
|
360
|
+
|
361
|
+
Creating a new `post` with the Group mounted:
|
362
|
+
|
363
|
+
```console
|
364
|
+
$ post = Post.create(attachments: "https://ucarecdn.com/dbc4e868-b7a6-43ff-a35f-2ebef935dc1b~1/")
|
365
|
+
```
|
366
|
+
|
367
|
+
Now the `post.attachments` is an Uploadcare::Rails::Group. Following methods are supported:
|
368
|
+
|
369
|
+
```console
|
370
|
+
# Store the file group on an Uploadcare server permanently:
|
371
|
+
$ post.attachments.store
|
372
|
+
# => {
|
373
|
+
# "cdn_url"=>"https://ucarecdn.com/dbc4e868-b7a6-43ff-a35f-2ebef935dc1b~1/",
|
374
|
+
# ...other group data...
|
375
|
+
# "files"=> [{
|
376
|
+
# "datetime_stored"=>"2021-07-29T08:31:45.668354Z",
|
377
|
+
# ...other file data...
|
378
|
+
# }]
|
379
|
+
# }
|
380
|
+
#
|
381
|
+
# Delete the file group from an Uploadcare server permanently:
|
382
|
+
$ post.attachments.delete
|
383
|
+
# => {
|
384
|
+
# "datetime_removed"=>"2021-07-30T09:19:30.797174Z",
|
385
|
+
# ...other group data...
|
386
|
+
# }
|
387
|
+
#
|
388
|
+
# Get CDN-url of an object attribute:
|
389
|
+
$ post.attachments.to_s
|
390
|
+
# => "https://ucarecdn.com/dbc4e868-b7a6-43ff-a35f-2ebef935dc1b~1/"
|
391
|
+
#
|
392
|
+
# Load object — works the same way as for the File:
|
393
|
+
$ post.attachments.load
|
394
|
+
# => {
|
395
|
+
# "cdn_url"=>"https://ucarecdn.com/dbc4e868-b7a6-43ff-a35f-2ebef935dc1b~1/",
|
396
|
+
# ...other group data...
|
397
|
+
# "files"=> [{
|
398
|
+
# "datetime_stored"=>"2021-07-29T08:31:45.668354Z",
|
399
|
+
# ...other file data...
|
400
|
+
# }]
|
401
|
+
# }
|
402
|
+
#
|
403
|
+
# Check if an attribute loaded from the server:
|
404
|
+
$ post.attachments.loaded?
|
405
|
+
# => true
|
406
|
+
#
|
407
|
+
# As we don't want to show (on the html-page) a file group itself,
|
408
|
+
# we can get CDN-urls for file that the group contains. No loading group or files needed.
|
409
|
+
# This works for images only:
|
410
|
+
$ post.attachments.transform_file_urls(quality: "better")
|
411
|
+
# => ["https://ucarecdn.com/dbc4e868-b7a6-43ff-a35f-2ebef935dc1b~1/nth/0/-/quality/better/"]
|
412
|
+
#
|
413
|
+
# If you want to get non-transformed file urls, use:
|
414
|
+
$ post.attachments.file_urls
|
415
|
+
# => ["https://ucarecdn.com/dbc4e868-b7a6-43ff-a35f-2ebef935dc1b~1/nth/0/"]
|
416
|
+
```
|
417
|
+
|
418
|
+
|
419
|
+
### Image Transformation
|
420
|
+
|
421
|
+
Uploadcare provides a way to transform images stored on Uploadcare services specifying a list of operations.
|
422
|
+
If an operation has just one option, you can specify it like key-value:
|
423
|
+
|
424
|
+
```console
|
425
|
+
$ post.picture.transform_url(quality: "better")
|
426
|
+
# => "https://ucarecdn.com/ebbb9929-eb92-4f52-a212-eecfdb19d27d/-/quality/better/"
|
427
|
+
```
|
428
|
+
|
429
|
+
and if an operation supports several options — just set them as a Hash:
|
430
|
+
|
431
|
+
```console
|
432
|
+
$ post.picture.transform_url(crop: { dimensions: "300x500", coords: "50, 50", alignment: "center" })
|
433
|
+
# => "https://ucarecdn.com/ebbb9929-eb92-4f52-a212-eecfdb19d27d/-/crop/300x500/50,50/center/"
|
434
|
+
```
|
435
|
+
|
436
|
+
Full list of operations and valid values can be found [here](https://uploadcare.com/docs/transformations/image/).
|
437
|
+
|
438
|
+
### Uploadcare API interfaces
|
439
|
+
|
440
|
+
Uploadcare provides [APIs](https://uploadcare.com/docs/start/api/) to manage files, group, projects, webhooks, video and documents conversion and file uploads. The gem has unified interfaces to use Uploadcare APIs in RailsApp.
|
441
|
+
|
442
|
+
### Upload API
|
443
|
+
|
444
|
+
[Upload Api](https://uploadcare.com/api-refs/upload-api/) provides methods to upload files in many ways.
|
445
|
+
|
446
|
+
#### Upload a single file
|
447
|
+
|
448
|
+
```console
|
449
|
+
# Load a file
|
450
|
+
$ file = File.open("kitten.png")
|
451
|
+
# => #<File:kitten.png>
|
452
|
+
# Upload file to Uploadcare
|
453
|
+
$ uploadcare_file = Uploadcare::UploadApi.upload_file(file)
|
454
|
+
# => {
|
455
|
+
# "uuid"=>"2d33999d-c74a-4ff9-99ea-abc23496b053",
|
456
|
+
# ...other file data...
|
457
|
+
# }
|
458
|
+
```
|
459
|
+
|
460
|
+
This method supports single file uploading and uploading files from an URL (depending on the type of first argument - can be either String (i.e. URL) or File).
|
461
|
+
|
462
|
+
```console
|
463
|
+
# Upload file from URL
|
464
|
+
$ url = "https://ucarecdn.com/80b807be-faad-4f01-bbbe-0bbde172b9de/1secVIDEO.mp4"
|
465
|
+
$ uploadcare_file = Uploadcare::UploadApi.upload_file(url)
|
466
|
+
# => [
|
467
|
+
# {
|
468
|
+
# "size"=>22108,
|
469
|
+
# "uuid"=>"b5ed5e1d-a939-4fe4-bfb2-31d3867bb6s6",
|
470
|
+
# "original_filename"=>"1 sec VIDEO.mp4",
|
471
|
+
# "is_image"=>false,
|
472
|
+
# "image_info"=>nil,
|
473
|
+
# "is_ready"=>true,
|
474
|
+
# "mime_type"=>"video/mp4"
|
475
|
+
# }
|
476
|
+
# ]
|
477
|
+
```
|
478
|
+
|
479
|
+
|
480
|
+
#### Upload several files
|
481
|
+
|
482
|
+
```console
|
483
|
+
# Load a file
|
484
|
+
$ file = File.open("kitten.png")
|
485
|
+
# => #<File:kitten.png>
|
486
|
+
# Upload several files to Uploadcare
|
487
|
+
$ uploadcare_file = Uploadcare::UploadApi.upload_files([file])
|
488
|
+
# => [
|
489
|
+
# {
|
490
|
+
# "uuid"=>"2dfc94e6-e74e-4014-9ff5-a71b8928f4fa",
|
491
|
+
# "original_filename"=>:"kitten.png"
|
492
|
+
# }
|
493
|
+
# ]
|
494
|
+
```
|
495
|
+
|
496
|
+
|
497
|
+
### File API
|
498
|
+
|
499
|
+
FileApi provides an interface to manage single files, stored on Uploadcare Servers.
|
500
|
+
|
501
|
+
#### Get files
|
502
|
+
|
503
|
+
```console
|
504
|
+
# Valid options:
|
505
|
+
# removed: [true|false]
|
506
|
+
# stored: [true|false]
|
507
|
+
# limit: (1..1000)
|
508
|
+
# ordering: ["datetime_uploaded"|"-datetime_uploaded"]
|
509
|
+
# from: A starting point for filtering files. The value depends on your ordering parameter value.
|
510
|
+
$ Uploadcare::FileApi.get_files(ordering: "datetime_uploaded", limit: 10)
|
511
|
+
# => {
|
512
|
+
# "next"=>nil,
|
513
|
+
# "previous"=>nil,
|
514
|
+
# "total"=>2,
|
515
|
+
# "per_page"=>10,
|
516
|
+
# "results"=> [
|
517
|
+
# {
|
518
|
+
# "datetime_removed"=>nil,
|
519
|
+
# ... file data ...
|
520
|
+
# }
|
521
|
+
# ]
|
522
|
+
# }
|
523
|
+
```
|
524
|
+
|
525
|
+
|
526
|
+
#### Get a file by UUID
|
527
|
+
|
528
|
+
```console
|
529
|
+
$ Uploadcare::FileApi.get_file("7b2b35b4-125b-4c1e-9305-12e8da8916eb")
|
530
|
+
# => {
|
531
|
+
# "cdn_url"=>"https://ucarecdn.com/7b2b35b4-125b-4c1e-9305-12e8da8916eb/",
|
532
|
+
# ...other file data...
|
533
|
+
# }
|
534
|
+
```
|
535
|
+
|
536
|
+
|
537
|
+
#### Copy a file to default storage. Source can be UID or full CDN link
|
538
|
+
|
539
|
+
```console
|
540
|
+
# Valid options:
|
541
|
+
# stored: [true|false]
|
542
|
+
$ Uploadcare::FileApi.local_copy_file("2d33999d-c74a-4ff9-99ea-abc23496b052", store: false)
|
543
|
+
# => {
|
544
|
+
# "uuid"=>"f486132c-2fa5-454e-9e70-93c5e01a7e04",
|
545
|
+
# ...other file data...
|
546
|
+
# }
|
547
|
+
```
|
548
|
+
|
549
|
+
#### Copy a file to custom storage. Source can be UID or full CDN link
|
550
|
+
|
551
|
+
```console
|
552
|
+
# Valid options:
|
553
|
+
# make_public: [true|false]
|
554
|
+
$ Uploadcare::FileApi.remote_copy_file("2d33999d-c74a-4ff9-99ea-abc23496b052", "mytarget", make_public: false)
|
555
|
+
# => {
|
556
|
+
# "uuid"=>"f486132c-2fa5-454e-9e70-93c5e01a7e04",
|
557
|
+
# ...other file data...
|
558
|
+
# }
|
559
|
+
```
|
560
|
+
|
561
|
+
|
562
|
+
#### Store a file by UUID
|
563
|
+
|
564
|
+
```console
|
565
|
+
$ Uploadcare::FileApi.store_file("2d33999d-c74a-4ff9-99ea-abc23496b052")
|
566
|
+
# => {
|
567
|
+
# "uuid"=>"2d33999d-c74a-4ff9-99ea-abc23496b052",
|
568
|
+
# ...other file data...
|
569
|
+
# }
|
570
|
+
```
|
571
|
+
|
572
|
+
|
573
|
+
#### Store several files by UUIDs
|
574
|
+
|
575
|
+
```console
|
576
|
+
$ Uploadcare::FileApi.store_files(["f486132c-2fa5-454e-9e70-93c5e01a7e04"])
|
577
|
+
# => {
|
578
|
+
# "result" => [
|
579
|
+
# {
|
580
|
+
# "uuid"=>"f486132c-2fa5-454e-9e70-93c5e01a7e04",
|
581
|
+
# ...other file data...
|
582
|
+
# }
|
583
|
+
# ]
|
584
|
+
# }
|
585
|
+
```
|
586
|
+
|
587
|
+
|
588
|
+
#### Delete a file by UUID
|
589
|
+
|
590
|
+
```console
|
591
|
+
$ Uploadcare::FileApi.delete_file("2d33999d-c74a-4ff9-99ea-abc23496b052")
|
592
|
+
# => {
|
593
|
+
# "uuid"=>"2d33999d-c74a-4ff9-99ea-abc23496b052",
|
594
|
+
# ...other file data...
|
595
|
+
# }
|
596
|
+
```
|
597
|
+
|
598
|
+
|
599
|
+
#### Delete several files by UUIDs
|
600
|
+
|
601
|
+
```console
|
602
|
+
$ Uploadcare::FileApi.delete_files(["f486132c-2fa5-454e-9e70-93c5e01a7e04"])
|
603
|
+
# => {
|
604
|
+
# "result" => [
|
605
|
+
# {
|
606
|
+
# "uuid"=>"f486132c-2fa5-454e-9e70-93c5e01a7e04",
|
607
|
+
# ...other file data...
|
608
|
+
# }
|
609
|
+
# ]
|
610
|
+
# }
|
611
|
+
```
|
612
|
+
|
613
|
+
|
614
|
+
### Group API
|
615
|
+
|
616
|
+
GroupApi provides an interface to manage file groups stored on Uploadcare Servers.
|
617
|
+
|
618
|
+
#### Get file groups
|
619
|
+
|
620
|
+
```console
|
621
|
+
# Valid options:
|
622
|
+
# limit: (1..1000)
|
623
|
+
# ordering: ["datetime_created"|"-datetime_created"]
|
624
|
+
# from: A starting point for filtering group lists. MUST be a datetime value with T used as a separator.
|
625
|
+
# example: "2015-01-02T10:00:00"
|
626
|
+
$ Uploadcare::GroupApi.get_groups(ordering: "datetime_uploaded", limit: 10)
|
627
|
+
# => {
|
628
|
+
# "next"=>"next"=>"https://api.uploadcare.com/groups/?ordering=datetime_uploaded&limit=10&from=2021-07-16T11%3A12%3A12.236280%2B00%3A00&offset=0",
|
629
|
+
# "previous"=>nil,
|
630
|
+
# "total"=>82,
|
631
|
+
# "per_page"=>10,
|
632
|
+
# "results"=> [
|
633
|
+
# {
|
634
|
+
# "id"=>"d476f4c9-44a9-4670-88a5-c3cf5a26b6c2~20",
|
635
|
+
# "datetime_created"=>"2021-07-16T11:03:01.182239Z",
|
636
|
+
# "datetime_stored"=>nil,
|
637
|
+
# "files_count"=>20,
|
638
|
+
# "cdn_url"=>"https://ucarecdn.com/d476f4c9-44a9-4670-88a5-c3cf5d16b6c2~20/",
|
639
|
+
# "url"=>"https://api.uploadcare.com/groups/d476f4c9-44a9-4670-83a5-c3cf5d26b6c2~20/"
|
640
|
+
# },
|
641
|
+
# ... other groups data ...
|
642
|
+
# ]
|
643
|
+
# }
|
644
|
+
```
|
645
|
+
|
646
|
+
|
647
|
+
#### Get a single file group by a group ID
|
648
|
+
|
649
|
+
```console
|
650
|
+
$ Uploadcare::GroupApi.get_group("d476f4c9-44a9-4670-88a5-c3cf5d26a6c2~20")
|
651
|
+
# => {
|
652
|
+
# "cdn_url"=>"https://ucarecdn.com/d476f4c9-44a9-4670-88a5-c3cf5d26a6c2~20/",
|
653
|
+
# ...other group data...
|
654
|
+
# "files"=> [{
|
655
|
+
# "datetime_stored"=>"2021-07-29T08:31:45.668354Z",
|
656
|
+
# ...other file data...
|
657
|
+
# }]
|
658
|
+
# }
|
659
|
+
```
|
660
|
+
|
661
|
+
|
662
|
+
#### Store files of a group by a group ID
|
663
|
+
|
664
|
+
```console
|
665
|
+
$ Uploadcare::GroupApi.store_group("d476f4c9-44a9-4670-88a5-c3cf5d26a6c2~20")
|
666
|
+
# => "200 OK"
|
667
|
+
```
|
668
|
+
|
669
|
+
|
670
|
+
#### Create a new group by file's uuids.
|
671
|
+
|
672
|
+
It is possible to specify transformed URLs with UUIDs of files OR just UUIDs.
|
673
|
+
|
674
|
+
```
|
675
|
+
NOTE: Be sure to add a trailing slash "/" to the URL in case of specifying transformed URLs.
|
676
|
+
```
|
677
|
+
|
678
|
+
```console
|
679
|
+
$ Uploadcare::GroupApi.create_group(["e08dec9e-7e25-49c5-810e-4c360d86bbae/-/resize/300x500/"])
|
680
|
+
# => {
|
681
|
+
# "cdn_url"=>"https://ucarecdn.com/d476f4c9-44a9-4670-88a5-c3cf5d26a6c2~1/",
|
682
|
+
# ...other group data...
|
683
|
+
# "files"=> [{
|
684
|
+
# "datetime_stored"=>"2021-07-29T08:31:45.668354Z",
|
685
|
+
# ...other file data...
|
686
|
+
# }]
|
687
|
+
# }
|
688
|
+
```
|
689
|
+
|
690
|
+
|
691
|
+
#### Delete a file group by its ID
|
692
|
+
|
693
|
+
```console
|
694
|
+
$ Uploadcare::GroupApi.delete_group("90c93e96-965b-4dd2-b323-39d9bd5f492c~1")
|
695
|
+
# => "200 OK"
|
696
|
+
```
|
697
|
+
|
698
|
+
|
699
|
+
### Project API
|
700
|
+
|
701
|
+
ProjectApi interface provides just one method - to get a configuration of your Uploadcare project.
|
702
|
+
|
703
|
+
```console
|
704
|
+
$ Uploadcare::ProjectApi.get_project
|
705
|
+
# => {
|
706
|
+
# "collaborators"=>[],
|
707
|
+
# "name"=>"New project",
|
708
|
+
# "pub_key"=>"your_public_key",
|
709
|
+
# "autostore_enabled"=>true
|
710
|
+
# }
|
711
|
+
```
|
712
|
+
|
713
|
+
|
714
|
+
### Webhook API
|
715
|
+
|
716
|
+
WebhookApi allows to manage Uploadcare webhooks.
|
717
|
+
|
718
|
+
#### Get all webhooks
|
719
|
+
|
720
|
+
This method returns a non-paginated list of webhooks set in your project
|
721
|
+
|
722
|
+
```console
|
723
|
+
$ Uploadcare::WebhookApi.get_webhooks
|
724
|
+
# => [{
|
725
|
+
# "id"=>815677,
|
726
|
+
# "created"=>"2021-08-02T05:02:14.588794Z",
|
727
|
+
# "updated"=>"2021-08-02T05:02:14.588814Z",
|
728
|
+
# "event"=>"file.uploaded",
|
729
|
+
# "target_url"=>"https://example.com",
|
730
|
+
# "project"=>123682,
|
731
|
+
# "is_active"=>true
|
732
|
+
# }]
|
733
|
+
```
|
734
|
+
|
735
|
+
|
736
|
+
#### Create a new webhook
|
737
|
+
|
738
|
+
This method requires an URL that is triggered by an event, for example, a file upload. A target URL MUST be unique for each project — event type combination.
|
739
|
+
|
740
|
+
Each webhook payload can be signed with a secret (the `signing_secret` option) to ensure that the request comes from the expected sender.
|
741
|
+
More info about secure webhooks [here](https://uploadcare.com/docs/security/secure-webhooks/).
|
742
|
+
|
743
|
+
```console
|
744
|
+
# Valid options:
|
745
|
+
# event: ["file.uploaded"]
|
746
|
+
# is_active: [true|false]
|
747
|
+
$ Uploadcare::WebhookApi.create_webhook("https://example.com", event: "file.uploaded", is_active: true, signing_secret: "some-secret")
|
748
|
+
# => {
|
749
|
+
# "id"=>815671,
|
750
|
+
# "created"=>"2021-08-02T05:02:14.588794Z",
|
751
|
+
# "updated"=>"2021-08-02T05:02:14.588814Z",
|
752
|
+
# "event"=>"file.uploaded",
|
753
|
+
# "target_url"=>"https://example.com",
|
754
|
+
# "project"=>123682,
|
755
|
+
# "is_active"=>true
|
756
|
+
# }
|
757
|
+
```
|
758
|
+
|
759
|
+
|
760
|
+
#### Update an existing webhook by ID
|
761
|
+
|
762
|
+
Updating a webhook is available if webhook ID is known. The ID is returned in a response on creating or listing webhooks. Setting a signing secret is supported when updating a webhook as well.
|
763
|
+
|
764
|
+
```console
|
765
|
+
# Valid options:
|
766
|
+
# event: Presently, we only support the "file.uploaded" event
|
767
|
+
# is_active: [true|false]
|
768
|
+
$ Uploadcare::WebhookApi.update_webhook("webhook_id", target_url: "https://example1.com", event: "file.uploaded", is_active: false, signing_secret: "some-secret")
|
769
|
+
# => {
|
770
|
+
# "id"=>815671,
|
771
|
+
# "created"=>"2021-08-02T05:02:14.588794Z",
|
772
|
+
# "updated"=>"2021-08-02T05:02:14.588814Z",
|
773
|
+
# "event"=>"file.uploaded",
|
774
|
+
# "target_url"=>"https://example1.com",
|
775
|
+
# "project"=>123682,
|
776
|
+
# "is_active"=>false
|
777
|
+
# }
|
778
|
+
```
|
779
|
+
|
780
|
+
|
781
|
+
#### Delete an existing webhook by a target_url
|
782
|
+
|
783
|
+
```console
|
784
|
+
$ Uploadcare::WebhookApi.delete_webhook("https://example1.com")
|
785
|
+
# => Success(nil)
|
786
|
+
```
|
787
|
+
|
788
|
+
### Conversion API
|
789
|
+
|
790
|
+
ConversionApi provides methods to manage video and documents conversion.
|
791
|
+
|
792
|
+
#### Convert a document
|
793
|
+
|
794
|
+
This method requires an UUID of a previously uploaded to Uploadcare file and target format.
|
795
|
+
If using an image format, you can also specify a page number that must be converted for a document containing pages.
|
796
|
+
More info about document conversion can be found [here](https://uploadcare.com/docs/transformations/document-conversion/).
|
797
|
+
|
798
|
+
```console
|
799
|
+
$ Uploadcare::ConversionApi.convert_document(
|
800
|
+
$ { uuid: "466740dd-cfad-4de4-9218-1ddc0edf7aa6", format: "png", page: 1 },
|
801
|
+
$ store: false
|
802
|
+
$ )
|
803
|
+
# => Success({
|
804
|
+
# :result=>[{
|
805
|
+
# :original_source=>"466740dd-cfad-4de4-9218-1ddc0edf7aa6/document/-/format/png/-/page/1/",
|
806
|
+
# :token=>21316034,
|
807
|
+
# :uuid=>"db6e52b8-cc03-4174-a07a-012be43b144e"
|
808
|
+
# }],
|
809
|
+
# :problems=>{}
|
810
|
+
# })
|
811
|
+
```
|
812
|
+
|
813
|
+
|
814
|
+
#### Get a document conversion job status
|
815
|
+
|
816
|
+
This method requires a token obtained in a response to the [convert_document](#convert-a-document) method.
|
817
|
+
|
818
|
+
```console
|
819
|
+
$ Uploadcare::ConversionApi.get_document_conversion_status(21316034)
|
820
|
+
# => Success({
|
821
|
+
# :result=>{
|
822
|
+
# :uuid=>"db6e52b8-cc03-4174-a07a-012be43b144e"
|
823
|
+
# },
|
824
|
+
# :error=>nil,
|
825
|
+
# :status=>"finished"
|
826
|
+
# })
|
827
|
+
```
|
828
|
+
|
829
|
+
|
830
|
+
#### Convert a video
|
831
|
+
|
832
|
+
Such as the document conversion method, this method requires an UUID of a previously uploaded to Uploadcare file.
|
833
|
+
Also you have several options to control the way a video will be converted. All of them are optional.
|
834
|
+
Description of valid options and other info about video conversion can be found [here](https://uploadcare.com/docs/transformations/video-encoding/).
|
835
|
+
|
836
|
+
```console
|
837
|
+
$ Uploadcare::ConversionApi.convert_video(
|
838
|
+
$ {
|
839
|
+
$ uuid: "466740dd-cfad-4de4-9218-1ddc0edf7aa6",
|
840
|
+
$ format: "ogg",
|
841
|
+
$ quality: "best",
|
842
|
+
$ cut: { start_time: "0:0:0.0", length: "0:0:1.0" },
|
843
|
+
$ thumbs: { N: 2, number: 1 }
|
844
|
+
$ },
|
845
|
+
$ store: false
|
846
|
+
$ )
|
847
|
+
# => Success({
|
848
|
+
# :result=>[{
|
849
|
+
# :original_source=>"80b807be-faad-4f01-bbbe-0bbde172b9de/video/-/size/600x400/change_ratio/-/quality/best/-/format/ogg/-/cut/0:0:0.0/0:0:1.0/-/thumbs~2/1/",
|
850
|
+
# :token=>916090555,
|
851
|
+
# :uuid=>"df597ef4-59e7-47ef-af5d-365d8409934c~2",
|
852
|
+
# :thumbnails_group_uuid=>"df597ef4-59e7-47ef-af5d-365d8409934c~2"
|
853
|
+
# }],
|
854
|
+
# :problems=>{}
|
855
|
+
# })
|
856
|
+
```
|
857
|
+
|
858
|
+
|
859
|
+
#### Get a video conversion job status
|
860
|
+
|
861
|
+
This method requires a token obtained in a response to the [convert_video](#convert-a-video) method.
|
862
|
+
|
863
|
+
```console
|
864
|
+
$ Uploadcare::ConversionApi.get_video_conversion_status(916090555)
|
865
|
+
# => Success({
|
866
|
+
# :result=>{
|
867
|
+
# :uuid=>"f0a3e66e-cd22-4397-ba0a-8a8becc925f9",
|
868
|
+
# :thumbnails_group_uuid=>"df597ef4-59e7-47ef-af5d-365d8409934c~2"
|
869
|
+
# },
|
870
|
+
# :error=>nil,
|
871
|
+
# :status=>"finished"
|
872
|
+
# })
|
873
|
+
```
|
874
|
+
|
875
|
+
|
876
|
+
### File Metadata Api
|
877
|
+
|
878
|
+
File metadata is additional, arbitrary data, associated with uploaded file.
|
879
|
+
As an example, you could store unique file identifier from your system.
|
880
|
+
Metadata is key-value data.
|
881
|
+
|
882
|
+
#### Get file's metadata keys and values
|
883
|
+
|
884
|
+
```console
|
885
|
+
$ Uploadcare::FileMetadataApi.file_metadata('f757ea10-8b1a-4361-9a7c-56bfa5d45176')
|
886
|
+
# => {:"sample-key"=>"sample-value"}
|
887
|
+
```
|
888
|
+
|
889
|
+
#### Get the value of a single metadata key
|
890
|
+
|
891
|
+
```console
|
892
|
+
$ Uploadcare::FileMetadataApi.file_metadata_value('f757ea10-8b1a-4361-9a7c-56bfa5d45176', 'sample-key')
|
893
|
+
# => "sample-value"
|
894
|
+
```
|
895
|
+
|
896
|
+
#### Update the value of a single metadata key
|
897
|
+
|
898
|
+
If the key does not exist, it will be created.
|
899
|
+
|
900
|
+
```console
|
901
|
+
$ Uploadcare::FileMetadataApi.update_file_metadata('f757ea10-8b1a-4361-9a7c-56bfa5d45176', 'sample-key', 'new-value')
|
902
|
+
# => "new-value"
|
903
|
+
```
|
904
|
+
|
905
|
+
#### Delete a file's metadata key
|
906
|
+
|
907
|
+
```console
|
908
|
+
$ Uploadcare::FileMetadataApi.delete_file_metadata('f757ea10-8b1a-4361-9a7c-56bfa5d45176', 'sample-key')
|
909
|
+
# => "200 OK"
|
910
|
+
```
|
911
|
+
|
912
|
+
|
913
|
+
### Add-Ons Api
|
914
|
+
|
915
|
+
An Add-On is an application implemented by Uploadcare that accepts uploaded files as an input and can produce other files and/or appdata as an output.
|
916
|
+
|
917
|
+
#### Execute AWS Rekognition Add-On for a given target to detect labels in an image
|
918
|
+
|
919
|
+
```
|
920
|
+
Note: Detected labels are stored in the file's appdata.
|
921
|
+
```
|
922
|
+
|
923
|
+
```console
|
924
|
+
$ Uploadcare::AddonsApi.rekognition_detect_labels('f757ea10-8b1a-4361-9a7c-56bfa5d45176')
|
925
|
+
# => {"request_id"=>"dfeaf81c-5c0d-49d5-8ed4-ac09bac7998e"}
|
926
|
+
```
|
927
|
+
|
928
|
+
#### Check the status of an Add-On execution request that had been started using the Execute Add-On operation
|
929
|
+
|
930
|
+
```console
|
931
|
+
$ Uploadcare::AddonsApi.rekognition_detect_labels_status('dfeaf81c-5c0d-49d5-8ed4-ac09bac7998e')
|
932
|
+
# => {"status"=>"done"}
|
933
|
+
```
|
934
|
+
|
935
|
+
#### Execute ClamAV virus checking Add-On for a given target
|
936
|
+
|
937
|
+
```console
|
938
|
+
$ Uploadcare::AddonsApi.virus_scan('dfeaf81c-5c0d-49d5-8ed4-ac09bac7998e')
|
939
|
+
# => {"request_id"=>"1b0126de-ace6-455b-82e2-25f4aa33fc6f"}
|
940
|
+
```
|
941
|
+
|
942
|
+
#### Check the status of an Add-On execution request that had been started using the Execute Add-On operation
|
943
|
+
|
944
|
+
```console
|
945
|
+
$ Uploadcare::AddonsApi.virus_scan_status('1b0126de-ace6-455b-82e2-25f4aa33fc6f')
|
946
|
+
# => {"status"=>"done"}
|
947
|
+
```
|
948
|
+
|
949
|
+
#### Execute remove.bg background image removal Add-On for a given target
|
950
|
+
|
951
|
+
```console
|
952
|
+
$ Uploadcare::AddonsApi.remove_bg('f757ea10-8b1a-4361-9a7c-56bfa5d45176')
|
953
|
+
# => {"request_id"=>"6d26a7d5-0955-4aeb-a9b1-c9776c83aa4c"}
|
954
|
+
```
|
955
|
+
|
956
|
+
#### Check the status of an Add-On execution request that had been started using the Execute Add-On operation
|
957
|
+
|
958
|
+
```console
|
959
|
+
$ Uploadcare::AddonsApi.remove_bg_status('6d26a7d5-0955-4aeb-a9b1-c9776c83aa4c')
|
960
|
+
# => {"status"=>"done", "result"=>{"file_id"=>"8f0a2a28-3ed7-481e-b415-ee3cce982aaa"}}
|
961
|
+
```
|
962
|
+
|
963
|
+
|
964
|
+
## Useful links
|
965
|
+
* [Uploadcare documentation](https://uploadcare.com/docs/?utm_source=github&utm_medium=referral&utm_campaign=uploadcare-rails)
|
966
|
+
* [Upload API reference](https://uploadcare.com/api-refs/upload-api/?utm_source=github&utm_medium=referral&utm_campaign=uploadcare-rails)
|
967
|
+
* [REST API reference](https://uploadcare.com/api-refs/rest-api/?utm_source=github&utm_medium=referral&utm_campaign=uploadcare-rails)
|
968
|
+
* [Changelog](./CHANGELOG.md)
|
969
|
+
* [Contributing guide](https://github.com/uploadcare/.github/blob/master/CONTRIBUTING.md)
|
970
|
+
* [Security policy](https://github.com/uploadcare/uploadcare-rails/security/policy)
|
971
|
+
* [Support](https://github.com/uploadcare/.github/blob/master/SUPPORT.md)
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
$LOAD_PATH.push File.expand_path('lib', __dir__)
|
4
|
+
|
5
|
+
# Maintain your gem's version:
|
6
|
+
require 'uploadcare/rails/version'
|
7
|
+
|
8
|
+
# Describe your gem and declare its dependencies:
|
9
|
+
Gem::Specification.new do |gem|
|
10
|
+
gem.required_ruby_version = '>= 2.7.0'
|
11
|
+
|
12
|
+
gem.name = 'uploadcare-rails'
|
13
|
+
gem.authors = ['@dmitrijivanchenko (Dmitrij Ivanchenko), @T0mbery (Andrey Aksenov)',
|
14
|
+
'kraft001 (Konstantin Rafalskii)']
|
15
|
+
gem.email = ['hello@uploadcare.com']
|
16
|
+
gem.summary = 'Rails gem for Uploadcare'
|
17
|
+
gem.description = <<~DESCRIPTION
|
18
|
+
Rails API client (based on uploadcare-ruby) that handles uploads
|
19
|
+
and further operations with files by wrapping Uploadcare Upload and REST APIs.
|
20
|
+
DESCRIPTION
|
21
|
+
gem.metadata = {
|
22
|
+
'source_code_uri' => 'https://github.com/uploadcare/uploadcare-rails',
|
23
|
+
'bug_tracker_uri' => 'https://github.com/uploadcare/uploadcare-rails/issues',
|
24
|
+
'changelog_uri' => 'https://github.com/uploadcare/uploadcare-rails/blob/main/CHANGELOG.md',
|
25
|
+
'documentation_uri' => 'https://www.rubydoc.info/gems/uploadcare-rails/',
|
26
|
+
'homepage_uri' => 'https://uploadcare.com/',
|
27
|
+
'rubygems_mfa_required' => 'true'
|
28
|
+
}
|
29
|
+
gem.homepage = 'https://uploadcare.com/'
|
30
|
+
gem.license = 'MIT'
|
31
|
+
|
32
|
+
gem.files = Dir[
|
33
|
+
'lib/**/*',
|
34
|
+
'Gemfile',
|
35
|
+
'Rakefile',
|
36
|
+
'uploadcare-rails.gemspec',
|
37
|
+
'LICENSE.txt',
|
38
|
+
'README.md',
|
39
|
+
'CHANGELOG.md'
|
40
|
+
]
|
41
|
+
|
42
|
+
gem.extra_rdoc_files = %w[README.md LICENSE.txt]
|
43
|
+
gem.rdoc_options = %w[--line-numbers --title Uploadcare --main README.rdoc --encoding=UTF-8]
|
44
|
+
|
45
|
+
gem.version = Uploadcare::Rails::VERSION
|
46
|
+
gem.add_dependency 'rails', '>= 6'
|
47
|
+
gem.add_dependency 'uploadcare-ruby', '>= 4.3'
|
48
|
+
|
49
|
+
gem.add_development_dependency 'rspec', '~> 3.12'
|
50
|
+
gem.add_development_dependency 'rspec-rails', '>= 5.1'
|
51
|
+
gem.add_development_dependency 'rubocop', '~> 1.48'
|
52
|
+
gem.add_development_dependency 'vcr', '~> 6.1'
|
53
|
+
gem.add_development_dependency 'webmock', '~> 3.18'
|
54
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uploadcare-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.3.
|
4
|
+
version: 3.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "@dmitrijivanchenko (Dmitrij Ivanchenko), @T0mbery (Andrey Aksenov)"
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-03-
|
12
|
+
date: 2023-03-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -116,8 +116,14 @@ email:
|
|
116
116
|
- hello@uploadcare.com
|
117
117
|
executables: []
|
118
118
|
extensions: []
|
119
|
-
extra_rdoc_files:
|
119
|
+
extra_rdoc_files:
|
120
|
+
- README.md
|
121
|
+
- LICENSE.txt
|
120
122
|
files:
|
123
|
+
- CHANGELOG.md
|
124
|
+
- Gemfile
|
125
|
+
- LICENSE.txt
|
126
|
+
- README.md
|
121
127
|
- Rakefile
|
122
128
|
- lib/generators/templates/uploadcare_config_template.erb
|
123
129
|
- lib/generators/uploadcare_config_generator.rb
|
@@ -150,16 +156,25 @@ files:
|
|
150
156
|
- lib/uploadcare/rails/services/id_extractor.rb
|
151
157
|
- lib/uploadcare/rails/transformations/image_transformations.rb
|
152
158
|
- lib/uploadcare/rails/version.rb
|
153
|
-
|
159
|
+
- uploadcare-rails.gemspec
|
160
|
+
homepage: https://uploadcare.com/
|
154
161
|
licenses:
|
155
162
|
- MIT
|
156
163
|
metadata:
|
157
|
-
|
164
|
+
source_code_uri: https://github.com/uploadcare/uploadcare-rails
|
158
165
|
bug_tracker_uri: https://github.com/uploadcare/uploadcare-rails/issues
|
159
166
|
changelog_uri: https://github.com/uploadcare/uploadcare-rails/blob/main/CHANGELOG.md
|
167
|
+
documentation_uri: https://www.rubydoc.info/gems/uploadcare-rails/
|
168
|
+
homepage_uri: https://uploadcare.com/
|
160
169
|
rubygems_mfa_required: 'true'
|
161
170
|
post_install_message:
|
162
|
-
rdoc_options:
|
171
|
+
rdoc_options:
|
172
|
+
- "--line-numbers"
|
173
|
+
- "--title"
|
174
|
+
- Uploadcare
|
175
|
+
- "--main"
|
176
|
+
- README.rdoc
|
177
|
+
- "--encoding=UTF-8"
|
163
178
|
require_paths:
|
164
179
|
- lib
|
165
180
|
required_ruby_version: !ruby/object:Gem::Requirement
|