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

  • SEARCH
  • Home
  • 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 8895535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:48:20+00:00 2026-06-14T23:48:20+00:00

I am uploading the pdf file in django form. But i need to perform

  • 0

I am uploading the pdf file in django form.

But i need to perform the validation on the pdf file by reading the contents of file and then checking and if its not valid then give some error message.

But i am not able to find how can i get the pdf file location so that i can read the file and do some test.

I don’t want to first save in temp location and then do validation and then delete the file

all i need is the path of the file so that i can run some system command on the file

  • 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-14T23:48:22+00:00Added an answer on June 14, 2026 at 11:48 pm

    The example below is based on the Basic file uploads example in the django docs. You can have a function in this example called check_pdf that does your validation on the pdf file and returns true/false based on whether it is valid. Depending on that you redirect the user to a success or invalid pdf page. This is the simplest way of doing it. You could do more and present specific error messages using the forms apis.

    from django.http import HttpResponseRedirect
    from django.shortcuts import render_to_response
    
    def upload_file(request):
        if request.method == 'POST':
            form = UploadFileForm(request.POST, request.FILES)
            if form.is_valid():
                if check_pdf(request.FILES['file'].name):
                    return HttpResponseRedirect('/success/url/')
                else:
                    return HttpResponseRedirect('/invalid_pdf/url/')
        else:
            form = UploadFileForm()
        return render_to_response('upload.html', {'form': form})
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm uploading a pdf via a ASP.NET web form and checking it's MIME. Sometimes
When uploading a PDF file from an HTML form, the mime-type Firefox (WinXP) provides
I am uploading file(pdf for now) like this: (It is uploading content of file
Can I use the PHP code below if the PDF file is not on
i have same problem. other files doc, xls uploads fine. but pdf uploading gives
How to validate the content-type of a file before uploading using JavaScript? I'm not
I'm uploading a pdf file from an iOS application to a Rails application. The
In my C# Windows application I want to upload a pdf file but in
I have a pdf file which I am uploading to my server. I can
I'd like to show a preview of a PDF file before uploading. Could anyone

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.