Skip to content

Instantly share code, notes, and snippets.

@philippbosch
Created August 9, 2011 10:41
Show Gist options
  • Select an option

  • Save philippbosch/1133738 to your computer and use it in GitHub Desktop.

Select an option

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
Copy Markdown

Thanks ;)

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

@saadullahaleem

Copy link
Copy Markdown

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
Copy Markdown

Thanks. This helped me a lot.

@liaogx

liaogx commented Jul 17, 2019

Copy link
Copy Markdown

It doesn't work!

@pomponchik

Copy link
Copy Markdown

its not working.

@philippbosch

Copy link
Copy Markdown
Author

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

@danielbenedykt

Copy link
Copy Markdown

Works great. Thanks

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