Skip to content

Add Base64AudioField - #230

Open
mmohajer9 wants to merge 1 commit into
Hipo:masterfrom
mmohajer9:feature/base64-audio-field
Open

mmohajer9 wants to merge 1 commit into
Hipo:masterfrom
mmohajer9:feature/base64-audio-field

Conversation

@mmohajer9

Copy link
Copy Markdown

What

Adds Base64AudioField — the audio sibling of Base64ImageField.

The library ships Base64ImageField, but the bare Base64FileField is abstract:
get_file_extension must be narrowed to a concrete file family by a subclass, so
handling base64 audio uploads today means every project writing the same subclass.

How

Mirrors Base64ImageField exactly:

  • format sniffed from the decoded bytes with filetype (the dependency
    Base64ImageField already uses — no new dependency),
  • default ALLOWED_TYPES: mp3, m4a, wav, ogg, flac, aac, amr, aiff,
  • same customization points (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

  • 4 tests in tests/test_fields.py following the Base64ImageSerializerTests
    conventions (plain and data-uri payloads, invalid base64, valid-base64-but-not-audio).
  • README section following the Base64ImageField section's format.

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
mmohajer9 force-pushed the feature/base64-audio-field branch from ef9c6dd to 6a00f6c Compare August 28, 2026 01:05
@mmohajer9

mmohajer9 commented Sep 7, 2026 •

Copy link
Copy Markdown
Author

@taylanpince @yigitguler
I appreciate your review on this PR :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant