Skip to main content

Helper module used in general django applications

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

django-aid-0.1.5.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

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

django_aid-0.1.5-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file django-aid-0.1.5.tar.gz.

File metadata

  • Download URL: django-aid-0.1.5.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.2

File hashes

Hashes for django-aid-0.1.5.tar.gz
Algorithm Hash digest
SHA256 1dcf0bae9d8c1566e1d6c86ccb6dce62d95ea0618c4d1c739cd4a8b3fa3dc555
MD5 8c80d7cb5d03068ecbcbde70d6e0072d
BLAKE2b-256 aadedde3916b65623d49437ae5f891a7def6dd86c5e62e72a4e0b647bf47d135

See more details on using hashes here.

File details

Details for the file django_aid-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: django_aid-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.2

File hashes

Hashes for django_aid-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 7352dfa290002868dc2e9560403bde7b9b3e6ef4da46f7252abea43cae091ec3
MD5 68f6e0120c72afc2c219b67720811e91
BLAKE2b-256 5e839d1e7ac6b719e8a9ee83f662a7c66beb4cfe33d7c5afe830e07145412cb0

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