Skip to content

Instantly share code, notes, and snippets.

@philippbosch
Created August 9, 2011 10:41
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philippbosch/1133738 to your computer and use it in GitHub Desktop.
Save philippbosch/1133738 to your computer and use it in GitHub Desktop.
Saving raw POST data to a file field in Django
from django.core.files.base import ContentFile
uploaded_file = ContentFile(request.raw_post_data)
uploaded_file.name = "filename.txt"
my_object.file = uploaded_file
my_object.save()
@JasonSpine
Copy link

Thanks ;)

My ContentFile wasn't saved because I didn't set it's name. Django should have better doc...

@saadullahaleem
Copy link

I would've saved quite a bit of time if I had come across this earlier. I had to upload an in-memory generated pdf. Thanks a lot.

@ijharulislam
Copy link

Thanks. This helped me a lot.

@liaogx
Copy link

liaogx commented Jul 17, 2019

It doesn't work!

@pomponchik
Copy link

its not working.

@philippbosch
Copy link
Author

@pomponchik thanks so much for the constructive and helpful comment.

@danielbenedykt
Copy link

Works great. Thanks

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