drf-base64-filename provides Serializer fields for using base64-encoded files with file names.
Project description
drf-base64-filename
drf-base64-filename provides Serializer fields for using base64-encoded files with file names.
Setup
Install drf-base64-filename to your Python environment
pip install drf-base64-filename
Usage
Sample Model
class SampleBase64ImageModel(models.Model):
parent = models.ForeignKey(
SampleParentModel,
on_delete=models.CASCADE,
related_name='image_set',
blank=True,
null=True,
)
image = models.ImageField(blank=True)
class SampleBase64FileModel(models.Model):
parent = models.ForeignKey(
SampleParentModel,
on_delete=models.CASCADE,
related_name='file_set',
blank=True,
null=True,
)
file = models.FileField(blank=True)
Serializer Field
class SampleNamedBase64ImageSerializer(serializers.ModelSerializer):
image = NamedBase64ImageField(required=False, allow_null=True)
class Meta:
model = SampleBase64ImageModel
fields = (
'id',
'image',
)
class SampleNamedBase64FileSerializer(serializers.ModelSerializer):
file = NamedBase64FileField(required=False, allow_null=True)
class Meta:
model = SampleBase64FileModel
fields = (
'id',
'file',
)
Sample request data
{
"image": {
"file_name": "pby.jpg",
"encoded_str": "aHR0cHM6Ly9naXRodWIuY29tL2xlZWhhbnllb25n"
}
}
Sample response data
{
"image": "http://test/media/pby.jpg"
}
Testing
cd test_project
pip install -r requirements.txt
pytest
Contributing
As an open source project, we welcome contributions. The code lives on GitHub
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file drf-base64-filename-1.0.8.tar.gz.
File metadata
- Download URL: drf-base64-filename-1.0.8.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b623bfe5ff2cfa2c5cb3ab4cc41f011f17d6ee01f1ef8b7b1d3b69eafd6f2c50
|
|
| MD5 |
ccb238c7319396dabc1de41c492e9090
|
|
| BLAKE2b-256 |
b42a735dfd2f6bc37f9eab33a75acaee9b3abaa035a9dc4141e4c3da8aa31904
|
File details
Details for the file drf_base64_filename-1.0.8-py3-none-any.whl.
File metadata
- Download URL: drf_base64_filename-1.0.8-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78feb4c2a3fd1614044fa3122e522f9860c069c9e17cb9dafba6891d32b8ea37
|
|
| MD5 |
586f0f1e027a3b5799b7306bd4bd26d7
|
|
| BLAKE2b-256 |
c2663a8251090937c89041f8e10739eae780e8f5bdb4d5b441d55c3f3f5ffdc7
|