Metadata-Version: 2.5
Name: django-s3-file-field-client
Version: 2.0.2
Summary: A Python client library for django-s3-file-field.
Project-URL: Repository, https://github.com/kitware-resonant/django-s3-file-field
Project-URL: Bug Reports, https://github.com/kitware-resonant/django-s3-file-field/issues
Maintainer-email: "Kitware, Inc." <kitware@kitware.com>
License-Expression: Apache-2.0
Keywords: django,django-widget,minio,s3
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Web Environment
Classifier: Framework :: Django
Classifier: Framework :: Django :: 5
Classifier: Framework :: Django :: 5.2
Classifier: Framework :: Django :: 6
Classifier: Framework :: Django :: 6.0
Classifier: Framework :: Django :: 6.1
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Requires-Python: >=3.12
Requires-Dist: requests
Requires-Dist: retryable-requests>=1.0
Requires-Dist: streamable>=2.0
Requires-Dist: tenacity
Requires-Dist: typing-extensions>=4.13; python_version < '3.15'
Description-Content-Type: text/markdown

# django-s3-file-field-client
[![PyPI](https://img.shields.io/pypi/v/django-s3-file-field-client)](https://pypi.org/project/django-s3-file-field-client/)

A Python client library for django-s3-file-field.

## Installation
```bash
pip install django-s3-file-field-client
```

## Usage
```python
import mimetypes
import pathlib
import requests
from s3_file_field_client import S3FileFieldClient

file_to_upload = pathlib.Path("/path/to/my_file.txt")
with (
    S3FileFieldClient(
        "http://localhost:8000/api/v1/s3-upload/",  # The path mounted in urlpatterns
        headers={"Authorization": "Token ..."},  # Headers for the API's requests; optional
    ) as s3ff_client,
    file_to_upload.open("rb") as file_stream,  # Open in binary mode
):
    field_value = s3ff_client.upload_file(
        file_stream=file_stream,  # This can be any seekable file-like object
        file_name=file_to_upload.name,
        file_content_type=mimetypes.guess_type(file_to_upload)[0],
        field_id="core.File.blob",  # The "<app>.<model>.<field>" to upload to
    )

requests.post(
    "http://localhost:8000/api/v1/file/",  # This is particular to the application
    headers={"Authorization": "Token ..."},
    json={
        "blob": field_value,  # This should match the field uploaded to (e.g. 'core.File.blob')
        ...: ...,  # Other fields for the POST request
    },
)
```

### Errors
A failed upload raises an `S3FileFieldError`, whose message is suitable for display. Its `status`
is the HTTP status of the response, if one was received, and its `__cause__` is the underlying
`requests` exception, when there is one.
