A Python client library for django-s3-file-field.
Project description
django-s3-file-field-client
A Python client library for django-s3-file-field.
Installation
pip install django-s3-file-field-client
Usage
import mimetypes
import pathlib
import requests
from s3_file_field_client import S3FileFieldClient
api_client = requests.Session() # This can be used to set authentication headers, etc.
s3ff_client = S3FileFieldClient(
'http://localhost:8000/api/v1/s3-upload/', # The path mounted in urlpatterns
api_client, # This argument is optional
)
file_to_upload = pathlib.Path('/path/to/my_file.txt')
with 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 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
)
api_client.post(
'http://localhost:8000/api/v1/file/', # This is particular to the application
json={
'blob': field_value, # This should match the field uploaded to (e.g. 'core.File.blob')
...: ..., # Other fields for the POST request
}
)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django_s3_file_field_client-1.0.1.tar.gz
.
File metadata
- Download URL: django_s3_file_field_client-1.0.1.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e5a2154d20556ce4603e89a0239c6bfea6d58c73d5e4df4a2d71d3deea787277 |
|
MD5 | 5e57013e492e61f16481cc14d56c5b48 |
|
BLAKE2b-256 | 8bc22a746134f26beadfcd099fe8b7574494858d0ded7979dec7c9e2ee1af544 |
Provenance
File details
Details for the file django_s3_file_field_client-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: django_s3_file_field_client-1.0.1-py3-none-any.whl
- Upload date:
- Size: 3.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29f6fcd0bcf60020867ef8407af09fe96b97d8883a828ea2e04ac30981305163 |
|
MD5 | de8b94ad9c700bd838def085772cb55a |
|
BLAKE2b-256 | c330edeec4725d1795dda41a580ce986cb8aa6879b25057c1e47c97894fe9966 |