You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can create a carrierwave uploader in order to attach pictures to your database objects as their attributes. To upload images without designating them as database attributes, skip to [this section](https://github.com/imagekit-developer/imagekit-ruby#file-upload).
59
-
65
+
(make sure to add service `:carrierwave` as shown in [initialization section](#Initialization))
60
66
```bash
61
67
rails g uploader <Uploading_attribute_name>
62
68
# For example, if you want to create an uploader for Avatar attribute, then use
@@ -66,8 +72,8 @@ rails g uploader Avatar
66
72
67
73
After that, you need to edit your generated uploader and make the following changes:
68
74
```ruby
69
-
#Set store as imagekit_store
70
-
storage :imagekit_store
75
+
#include this module inside the top of the uploader class
76
+
includeImageKitIo::CarrierWave
71
77
72
78
# If you want to add uploading options, then create this method inside the uploader file as an example
73
79
@@ -108,6 +114,31 @@ Get image url:
108
114
@employee.avatar.url_with(options)
109
115
```
110
116
117
+
#### ActiveStorage
118
+
119
+
Once you [install](https://guides.rubyonrails.org/active_storage_overview.html#setup) the active_storage gem, then any model can have the attachment using `has_one_attached` or `has_many_attached` like below:
120
+
121
+
```ruby
122
+
classEmployee < ApplicationRecord
123
+
has_one_attached :avatar
124
+
end
125
+
```
126
+
Now lets configure active_storage as a service for the imagekitio.
127
+
128
+
First add `:active_storage` in initializer file.
129
+
130
+
```ruby
131
+
config.service =:active_storage
132
+
```
133
+
134
+
Then add the imagekitio service in the `storage.yml` file:
135
+
136
+
```ruby
137
+
imagekitio:
138
+
service:ImageKitIo
139
+
```
140
+
141
+
111
142
## Usage
112
143
113
144
You can use this Ruby SDK for three different kinds of methods - URL generation, file upload, and file management.
@@ -126,6 +157,7 @@ about paths with different kinds of origins.
Copy file from one path to another path using the source file path and the destination path as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/copy-file)
Move file from one folder to another folder using the source file path and destination path as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/move-file)
Delete a file as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/delete-file). The method accepts the file ID of the file that has to be deleted.
381
437
382
438
```ruby
383
439
imagekitio.delete_file(file_id)
384
440
```
385
441
386
-
**6. Bulk File Delete by IDs**
442
+
**9. Bulk File Delete by IDs**
387
443
Delete a file as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/delete-files-bulk). The method accepts a list of file IDs of files that has to be
blob_record.service.download(blob_record.key) do |chunk|
475
+
temp_file.write(chunk)
476
+
end
477
+
```
478
+
479
+
**13. Add Bulk Tags**
480
+
481
+
Add multiple tags on multiple files using array of file ids and array of tags as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/add-tags-bulk)
Remove multiple tags from multiple files using array of file ids and array of tags as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/remove-tags-bulk)
Delete folder as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/delete-folder)
523
+
524
+
```ruby
525
+
imagekitio.delete_folder('folder/to/delete')
526
+
```
527
+
528
+
**19. Bulk Job Status**
529
+
530
+
Get the bulk job status as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/copy-move-folder-status)
531
+
532
+
```ruby
533
+
imagekitio.bulk_job_status('job_id')
534
+
```
535
+
536
+
**20. Create Custom Metadata Fields**
537
+
538
+
Create custom metadata fields as per the [API documentation here](https://docs.imagekit.io/api-reference/custom-metadata-fields-api/create-custom-metadata-field)
539
+
540
+
```ruby
541
+
542
+
imagekitio.create_custom_metadata_fields(
543
+
'price',
544
+
'price_label',
545
+
{
546
+
type:'Number',
547
+
minValue:100,
548
+
maxValue:300
549
+
}
550
+
)
551
+
```
552
+
553
+
**21. Get Custom Metadata Fields**
554
+
555
+
Get the custom metadata fields as per the [API documentation here](https://docs.imagekit.io/api-reference/custom-metadata-fields-api/get-custom-metadata-field)
556
+
557
+
```ruby
558
+
imagekitio.get_custom_metadata_fields
559
+
```
560
+
561
+
**22. Update Custom Metadata Fields**
562
+
563
+
Update custom metadata fields as per the [API documentation here](https://docs.imagekit.io/api-reference/custom-metadata-fields-api/update-custom-metadata-field)
Delete custom metadata fields as per the [API documentation here](https://docs.imagekit.io/api-reference/custom-metadata-fields-api/delete-custom-metadata-field)
This is under [samples/rails_app](https://github.com/imagekit-developer/imagekit-ruby/blob/master/samples/rails_app) directory. Follow the instructions below to set up a rails application.
This sample project is using the Sqlite3 database. If you are getting `sqlite3` gem installation error, then install sqlite3 first, then again run `bundle install`.
0 commit comments