Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

drf-base64-filename-1.0.10.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

drf_base64_filename-1.0.10-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file drf-base64-filename-1.0.10.tar.gz.

File metadata

  • Download URL: drf-base64-filename-1.0.10.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for drf-base64-filename-1.0.10.tar.gz
Algorithm Hash digest
SHA256 bce1588cba0c544cda0b9330879141fcf10507dfbd97b06629ce4b09de4b06ac
MD5 4dbc2adf5da6cbe894acba9fd2abe1b3
BLAKE2b-256 93f76c66baf74542821d875ff4be5befdcd43153c14bcf54add8f5229c1a6197

See more details on using hashes here.

File details

Details for the file drf_base64_filename-1.0.10-py3-none-any.whl.

File metadata

File hashes

Hashes for drf_base64_filename-1.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 b04584d79cf29848d76301a0a2d445fb3acc0c8a913497d12788ebfe75aa85a0
MD5 2ac6709d90198e17f5592f6af21f8a77
BLAKE2b-256 557ead8777228f79433a8b83fae2caa229ee934552b5f68b3405bc5793b66d2b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page