Skip to content

Commit 17a776a

Browse files
committed
fix(docs): update README examples for file uploads and remove obsolete parameters
1 parent f1687c0 commit 17a776a

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

README.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,36 +53,35 @@ require "bundler/setup"
5353
require "imagekit"
5454

5555
image_kit = Imagekit::Client.new(
56-
private_key: ENV["IMAGEKIT_PRIVATE_KEY"], # This is the default and can be omitted
57-
password: ENV["OPTIONAL_IMAGEKIT_IGNORES_THIS"] # This is the default and can be omitted
56+
private_key: ENV["IMAGEKIT_PRIVATE_KEY"] # This is the default and can be omitted
5857
)
5958

6059
response = image_kit.files.upload(
61-
file: StringIO.new("https://www.example.com/public-url.jpg"),
60+
file: Pathname("/path/to/file"),
6261
file_name: "file-name.jpg"
6362
)
6463

65-
puts(response.videoCodec)
64+
puts(response.file_id)
6665
```
6766

6867
### File uploads
6968

70-
Request parameters that correspond to file uploads can be passed as raw contents, a [`Pathname`](https://rubyapi.org/3.2/o/pathname) instance, [`StringIO`](https://rubyapi.org/3.2/o/stringio), or more.
69+
Request parameters that correspond to file uploads can be passed as raw contents, a [`Pathname`](https://rubyapi.org/3.2/o/pathname) instance, or an `IO` stream.
7170

7271
```ruby
7372
require "pathname"
7473

75-
# Use `Pathname` to send the filename and/or avoid paging a large file into memory:
74+
# Use `Pathname` to stream from disk (memory efficient, supports retries):
7675
response = image_kit.files.upload(file: Pathname("/path/to/file"))
7776

78-
# Alternatively, pass file contents or a `StringIO` directly:
77+
# Or pass file contents directly
7978
response = image_kit.files.upload(file: File.read("/path/to/file"))
8079

81-
# Or, to control the filename and/or content type:
82-
file = Imagekit::FilePart.new(File.read("/path/to/file"), filename: "/path/to/file", content_type: "")
80+
# Or control filename and content type with FilePart:
81+
file = Imagekit::FilePart.new(File.read("/path/to/file"), filename: "custom.jpg", content_type: "image/jpeg")
8382
response = image_kit.files.upload(file: file)
8483

85-
puts(response.videoCodec)
84+
puts(response.file_id)
8685
```
8786

8887
Note that you can also pass a raw `IO` descriptor, but this disables retries, as the library can't be sure if the descriptor is a file or pipe (which cannot be rewound).

0 commit comments

Comments
 (0)