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 8371657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:13:00+00:00 2026-06-09T14:13:00+00:00

am trying yo do this using tornado and pil and mongodb. avat = self.request.files[‘avatar’][0][body]

  • 0

am trying yo do this using tornado and pil and mongodb.

avat = self.request.files['avatar'][0]["body"]
nomfich = self.request.files['avatar'][0]["filename"]

try:
    image = Image.open(StringIO.StringIO(buf=avat))
    size = image.size
    type = image.format

    avatar = r"/profile-images/{0}/{1}".format(pseudo, nomfich)

except IOError:
    self.redirect("/erreur-im")

and the database code:

user={
    "pseudo": pseudo, 
    "password":password, 
    "email":email, 
    "tel":tel, 
    "commune":commune,    
    "statut":statut, 
    "nom":nom, 
    "prenom":prenom, 
    "daten":daten, 
    "sexe":sexe, 
    "avatar":avatar
}

self.db.essog.insert(user)  

and it worked ok, the “avatar” is saved, but there in no image, it saves only a name!

my problem is:

  • to understand how database deals with pictures, must i make image.save(path, format), but the path, is it a path of a normal system path (windows, or linux)?
  • the profile is simple, and i’ve limited the picture upload to 500ko, and the document in mongodb is 16mb, so the document will handle the entire profile, but must i use gridFS even for small document when it contains picture?
    the key problem is in path of the picture saving, am stuck, and it’s the first time i deal with database, so am sorry for that question.
  • 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-06-09T14:13:02+00:00Added an answer on June 9, 2026 at 2:13 pm

    You don’t necessarily need GridFS for storing files in MongoDB, but it surely makes it a nicer experience, because it handles the splitting and saving of the binary data, while making the metadata also available. You can then store an ID in your User document to the avatar picture.

    That aside, you could also store binary data directly in your documents, though in your code you are not saving the data. You simply are opening it with PIL.Image, but then doing nothing with it.

    Assuming you are using pymongo for your driver, I think what you can do is just wrap the binary data in a Binary container, and then store it. This is untested by me, but I assume it should work:

    from pymongo.binary import Binary
    
    binary_avatar = Binary(avat)
    
    user={
        ...
        "avatar":avatar,
        "avatar_file": binary_avatar
        ...
    }
    

    Now that being said… just make it easier on yourself and use GridFS. That is what it is meant for.

    If you were to use GridFS, it might look like this:

    from gridfs import GridFS
    
    avat_ctype = self.request.files['avatar'][0]["content_type"]
    
    fs = GridFS(db)
    avatar_id = fs.put(avat, content_type=avat_ctype, filename=nomfich)
    
    user={
        ...
        "avatar_name":avatar,
        "avatar_id": avatar_id
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying this: using DocumentFormat.OpenXml.Packaging; using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(fileNameDocx as string, true))
I'm trying to do this: using(var context = new SampleEntities()) { User user =
I am trying to achieve this using Expression Blend 3. I need that every
How to set entire HTML in MSHTML? I am trying using this assignment: (Document
I'm trying to retrieve this page using Apache HttpClient: http://quick-dish.tablespoon.com/ Unfortunately, when I try
I'm trying to follow this tutorial using StructureMap : http://iridescence.no/post/Constructor-Injection-for-ASPNET-MVC-Action-Filters.aspx What I'm trying to
I am trying to make this button using CSS3: But my button looks like
I am trying to follow this tutorial ( Using-core-plot-in-an-iphone-application ). When I try to
I'm trying to implement this scenario using Unity and i can't figure out how
I'm trying to write this code using mostly arrays. I'm trying to get Correct

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.