django file field from base64

import base64 from django.core.files.base import ContentFile

Assuming you have a base64 encoded file string named base64_string

base64_string = "..." # Replace with your actual base64 encoded string

Decode the base64 string into bytes

decoded_file = base64.b64decode(base64_string)

Create a ContentFile object from the decoded bytes

file_content = ContentFile(decoded_file, name="example_file.txt")

Now you can use this file_content object to save it to a FileField in Django