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"
}

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.3.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

drf_base64_filename-1.0.3-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: drf-base64-filename-1.0.3.tar.gz
  • Upload date:
  • Size: 4.2 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.3.tar.gz
Algorithm Hash digest
SHA256 c59880678100991738be718f0cf8108644644804fedc93da028cb5c3b90f3491
MD5 9c399ba4abc580b8ba41118f1edcecc2
BLAKE2b-256 d6f73d4300ab126f0e7caf1c699b08b3fae13a34519c9f3e60e1107f060b057c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for drf_base64_filename-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6dd74a6479f8394e7a843fd3a3c882b15849fe31c08b9360b8a6a30c804ce6db
MD5 cd1d044051d15a52f51f9d8dacd0b249
BLAKE2b-256 96f00a8a5bc20e3234c4a51b49155572e3647e2b01f804c43f3764ee199fe46f

See more details on using hashes here.

Supported by

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