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
Close
Hashes for drf-base64-filename-1.0.9.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18a45b39a7f73f2537234863c05ff0b3d1a9d1420ba159532e4a0ff23fa4943f |
|
MD5 | bf23ee4f912680e2c23505eed36fc34f |
|
BLAKE2b-256 | 99d7c1ffc1100a6d294e7781ccfd958dc5e96b3732d36ac5179690ddabe3103d |
Close
Hashes for drf_base64_filename-1.0.9-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 944812e3a937fb9093a397a569e2191398e5937a4efed99f96c9266a7c3cff3e |
|
MD5 | ca9b6a7dd731e12606ec35032d01e7bb |
|
BLAKE2b-256 | 2236c12fce3b16d0dae249f4422a533ea2da6eff08ddac24b68653e880ad8a88 |