Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Readme update #280

Merged
merged 26 commits into from
Feb 26, 2024
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 42 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Build file handling in minutes. Upload or accept UGC, store, transform, optimize
* [Features](#features)
* [Documentation](#documentation)
* [Requirements and installation](#requirements-and-installation)
* [Usage example](#usage-example)
* [Usage examples](#usage-examples)
<!-- * [Use cases](#use-cases) -->
* [Demo app (Docker)](#demo-app)
* [Suggestions and questions](#suggestions-and-questions)
Expand Down Expand Up @@ -78,11 +78,50 @@ To use in Django project install with extra dependencies:
pip install pyuploadcare[django]
```

## Usage example
## Usage examples

After package [installation](#requirements-and-installation), you’ll need API keys: public and secret. Get them in [Uploadcare dashboard](https://app.uploadcare.com/projects/-/api-keys). If you don’t have an account yet, you can use demo keys, as in example. However, the files on demo account are regularly removed, so create an account as soon as Uploadcare catches your fancy.

In these examples we’re going to use the aforementioned demo keys.

### Basic usage

<!-- TODO: simple upload via API request / and maybe something more-->
Let’s start with the basics. Say, you want to upload a file:

```python
from pyuploadcare import Uploadcare

uploadcare = Uploadcare(public_key="demopublickey", secret_key="demoprivatekey")
with open("sample-file.jpeg", "rb") as file_object:
ucare_file = uploadcare.upload(file_object)
```

And your file is now uploaded to the Uploadcare CDN. But how do you access it from the web? It’s really simple:

```python
print(ucare_file.cdn_url) # file URL, e.g.: https://ucarecdn.com/7d4e9387-26c2-4e58-840e-9254f1871c94/
```

If you don’t have the “Automatic file storing” setting enabled in your project, don’t forget to store the uploaded file:
evgkirov marked this conversation as resolved.
Show resolved Hide resolved

```python
ucare_file.store()
print(ucare_file.is_stored) # True
```

A whole slew of other file operations are available. Do you want to crop your image, but don't want important information (faces, objects) to be cropped? You can do that with content-aware (“smart”) crop:

```python
from pyuploadcare.transformations.image import ImageTransformation, ScaleCropMode

# These two function calls are equivalent
ucare_file.set_effects("scale_crop/512x512/smart/")
ucare_file.set_effects(ImageTransformation().scale_crop(512, 512, mode=ScaleCropMode.smart))

print(ucare_file.cdn_url) # https://ucarecdn.com/7d4e9387-26c2-4e58-840e-9254f1871c94/-/scale_crop/512x512/smart/
```

There’s a lot more to uncover. For more information please refer to the [documentation](#documentation).

### Django integration

Expand All @@ -91,8 +130,6 @@ pip install pyuploadcare[django]
<!-- TODO: Update it with "and deliver an image" -->
rsedykh marked this conversation as resolved.
Show resolved Hide resolved
Let's add [File Uploader](https://uploadcare.com/docs/file-uploader/) to an existing Django project.
evgkirov marked this conversation as resolved.
Show resolved Hide resolved

After package [installation](#requirements-and-installation), you’ll need API keys: public and secret. Get them in [Uploadcare dashboard](https://app.uploadcare.com/projects/-/api-keys). If you don’t have an account yet, you can use demo keys, as in example. However, the files on demo account are regularly removed, so create an account as soon as Uploadcare catches your fancy.

Assume you have a Django project with gallery app.

Add `pyuploadcare.dj` into `INSTALLED_APPS`:
Expand Down
Loading