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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:42:49+00:00 2026-05-16T08:42:49+00:00

In certain situation users can send temporary files to my server. I would like

  • 0

In certain situation users can send temporary files to my server. I would like to keep track of those temporary files (since they are used later and I would like to know, when I can remove them – or when they weren’t used and can be collected). What kind of model should I use for it? I will send those files using AJAX (and iframe).

EDIT

If I use in the model FileField, how should I handle file upload? Could you show some example snippet, how my function should put file from request.FILES to a FielField.

  • 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-16T08:42:50+00:00Added an answer on May 16, 2026 at 8:42 am

    How you store the files is independent of whether or not they come via AJAX. Your view will still need to process the multipart form data, and store it in your DB and server filesystem, like any other uploaded file in Django.

    As far as the model goes, how about something like this?

    class TemporaryFileWrapper(models.Model):
       """
       Holds an arbitrary file and notes when it was last accessed
       """
       uploaded_file = models.FileField(upload_to="/foo/bar/baz/")
       uploading_user = models.ForeignKey(User)
       uploaded = models.DateTimeField(blank=True, null=True, auto_now_add=True)          
       last_accessed = models.DateTimeField(blank=True, null=True, 
                                            auto_now_add=False, auto_now=False)
    
    
       def read_file(record_read=True):
          #...some code here to read the uploaded_file
          if record_read:
              self.last_accessed = datetime.datetime.now()
              self.save()
    

    For basic file upload handling see the official documentation, but where the example has the handle_uploaded_file() method, you need some code that creates a TemporaryFileWrapper object, something like this, depending on your needs:

    ....
    form = ProviderSelfEditForm(request.POST, request.FILES) #this is where you bind files and postdata to the form from the HTTP request
    if form.is_valid():
         temp_file_wrapper = TemporaryFileWrapper()
         temp_file_wrapper.uploaded_file = 
                           form.cleaned_data['name_of_file_field_in_your_form']
         temp_file_wrapper.uploading_user = request.user #needs an authenticated user
         temp_file_wrapper.save()
    
         return HttpResponseRedirect('/success/url/')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.