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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:38:32+00:00 2026-05-15T10:38:32+00:00

I am uploading some .doc and .txt documents on my server, and i’d like

  • 0

I am uploading some .doc and .txt documents on my server, and i’d like to have two options:
-the user to be able to download the document
-the user to be able to read it online
i’ve read some code for the download function, but it doesn’t seem to work.

my code:

def download_course(request, id):
    course = Courses.objects.get(pk = id)
    response = HttpResponse(mimetype='application/force-download')
    response['Content-Disposition'] = 'attachment; filename=%s' % smart_str(file_name)
    response['X-Sendfile'] = smart_str(/root/)
    return response

def save_course(request, classname):
   classroom = Classroom.objects.get(classname = classname)
   if request.method == 'POST':
        form = CoursesForm(request.POST, request.FILES)
        if form.is_valid():
           handle_uploaded_file(request.FILES['course'])
           new_obj = form.save(commit=False)
           new_obj.creator = request.user
           new_obj.classroom = classroom
           new_obj.save()
           return HttpResponseRedirect('.')    
   else:
           form = CoursesForm()     
   return render_to_response('courses/new_course.html', {
           'form': form,
           }, 
          context_instance=RequestContext(request)) 


def handle_uploaded_file(f):
    destination = open('root', 'wb+')
    for chunk in f.chunks():
        destination.write(chunk)

    destination.close()

any clue?
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-15T10:38:33+00:00Added an answer on May 15, 2026 at 10:38 am

    Should the response[‘X-Sendfile’] be pointing to the file? It looks like it’s only pointing at ‘/root/’, which I’m guessing is just a directory. Maybe it should look more like this:

    def download_course(request, id):
        course = Courses.objects.get(pk = id)
        path_to_file = get_path_to_course_download(course)
    
        response = HttpResponse(mimetype='application/force-download')
        response['Content-Disposition'] = 'attachment; filename=%s' % smart_str(file_name)
        response['X-Sendfile'] = smart_str(path_to_file)
        return response
    

    Where get_path_to_course_download returns the location of the download in the file system (ex: /path/to/where/handle_uploaded_files/saves/files/the_file.doc)

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

Sidebar

Related Questions

I have some command-line ruby scripts for things like pre-processing text files before uploading
I am currently looking in to some file uploading using Java Server Faces. I've
I have already gone through some codings, and I found some interrupts in uploading.
I have a django app with some model for uploading files. I need to
We have a requirement for people to be able to look at documents people
Well like many other I encountered some problems while uploading my binary to appstore.
I have seen some PHP scripts for uploading files and images but didn't find
I have some kind of message board and I want visitors be able to
Can anyone give me some idea about uploading data from excel to access database
Can you run some script before the uploading of a file starts in php?

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.