Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6083845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:27:05+00:00 2026-05-23T11:27:05+00:00

I need to send a models.FileField as an email attachment using Django. I’ve seen

  • 0

I need to send a models.FileField as an email attachment using Django. I’ve seen snippets that show how to do this with the raw request.FILES data (which still contains the Content-Type), but have not been able to find anything that shows how to do it once you’ve already saved the file in a models.FileField. The content type seems to be inaccessible from the models.FileField.

Can someone give me an example of how this would work? I’m beginning to think that I might have to store the Content-Type in the model when I save the file.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:27:05+00:00Added an answer on May 23, 2026 at 11:27 am

    I would just not supply a content type and let the recipient’s email client work it out. Unless it will be something unusual it shouldn’t be a problem.

    RFC2616 states:

    If and only if the media type is not
    given by a Content-Type field, the
    recipient MAY attempt to guess the
    media type via inspection of its
    content and/or the name extension(s)
    of the URI used to identify the
    resource.

    but…
    If you want to specify it then storing the content type on upload is a very good idea. It should be noted that django’s own docs say to verify the data from users

    If you are on a *unix OS you could try to guess/inspect it:

    import subprocess
    subprocess.check_output(['file', '-b', '--mime', filename]) 
    

    (from How to find the mime type of a file in python? )

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We need to send email which contains Pound (currency) symbols in ColdFusion. Before sending
I am trying to send a sample email from my rails application. this is
We need to send newsletter/messages to our users at certain times. This is done
I need send certain attributes(say, human readable user name) from server to client after
I need to send hundreds of newsletters, but would like to check first if
I need to send and receive data over serial connections (RS-232 and RS-422). How
I need to send MMS thought a C# application. I have already found 2
I need to send a very specific (non-standard) string to an FTP server: dir
I need to send PUT and DELETE along with POST, GET to a REST
I need to send a CSV file in HTTP response. How can I set

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.