Conversation
drf-extra-fields ships Base64ImageField but no audio equivalent, and the bare Base64FileField is abstract (get_file_extension must be narrowed to a concrete file family). This adds the audio sibling: the format is sniffed from the decoded bytes with the filetype dependency the image field already uses, so the stored file carries a correct extension. Covers mp3, m4a, wav, ogg, flac, aac, amr and aiff, with the same customization points as the image field (ALLOWED_TYPES, INVALID_FILE_MESSAGE, INVALID_TYPE_MESSAGE).
mmohajer9
force-pushed
the
feature/base64-audio-field
branch
from
August 28, 2026 01:05
ef9c6dd to
6a00f6c
Compare
Author
|
@taylanpince @yigitguler |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds
Base64AudioField— the audio sibling ofBase64ImageField.The library ships
Base64ImageField, but the bareBase64FileFieldis abstract:get_file_extensionmust be narrowed to a concrete file family by a subclass, sohandling base64 audio uploads today means every project writing the same subclass.
How
Mirrors
Base64ImageFieldexactly:filetype(the dependencyBase64ImageFieldalready uses — no new dependency),ALLOWED_TYPES:mp3,m4a,wav,ogg,flac,aac,amr,aiff,ALLOWED_TYPES,INVALID_FILE_MESSAGE,INVALID_TYPE_MESSAGE).Detecting the type from content (rather than trusting a filename) matters for audio
in particular: transcription SDKs and players key off the extension of the stored
file.
Tests / docs
tests/test_fields.pyfollowing theBase64ImageSerializerTestsconventions (plain and data-uri payloads, invalid base64, valid-base64-but-not-audio).
Base64ImageFieldsection's format.