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
Close
Hashes for django_s3_file_field_client-1.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1a94c65397e491f4a2f5c2989fd82a4048e14337c72eb8e742feaa28d468e12 |
|
MD5 | d336ab916f1915f0eaf53da5679bf9eb |
|
BLAKE2b-256 | 63a49eb97d4e67b9240d4e2ef4c3418af64a16087e56edf54663b269adec04ae |
Close
Hashes for django_s3_file_field_client-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a4993ceca266fde62687d342b38d6f3521feec7a01cbdf35859667bf7eafd56 |
|
MD5 | 6bf42682fcc0eecc657ae2dc61a2d3c5 |
|
BLAKE2b-256 | 9e3129edf5ae7ad95ad33f8d4d0b9e7a5aee1b2dd52d54d530f18ea4ad431a37 |