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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:44:26+00:00 2026-06-10T10:44:26+00:00

I have used Django File Upload Progress process for getting progress but getting error

  • 0

I have used Django File Upload Progress process for getting progress but getting error pliks.upload" does not define a "UploadProgressCachedHandler" upload handler backend.

Steps i followed is

1) Create a folder upload and add file upload handler(UploadProgressCachedHandler.py) to it.

    from django.core.files.uploadhandler import FileUploadHandler
    from django.core.cache import cache
    class UploadProgressCachedHandler(FileUploadHandler):
        """
        Tracks progress for file uploads.
        The http post request must contain a header or query parameter, 'X-Progress-ID'
        which should contain a unique string to identify the upload to be tracked.

        Copied from:
        http://djangosnippets.org/snippets/678/

        See views.py for upload_progress function...
        """

        def __init__(self, request=None):
            super(UploadProgressCachedHandler, self).__init__(request)
            self.progress_id = None
            self.cache_key = None

        def handle_raw_input(self, input_data, META, content_length, boundary, encoding=None):
            self.content_length = content_length
            if 'X-Progress-ID' in self.request.GET :
                self.progress_id = self.request.GET['X-Progress-ID']
            elif 'X-Progress-ID' in self.request.META:
                self.progress_id = self.request.META['X-Progress-ID']
            if self.progress_id:
                self.cache_key = "%s_%s" % (self.request.META['REMOTE_ADDR'], self.progress_id )
                cache.set(self.cache_key, {
                    'length': self.content_length,
                    'uploaded' : 0
                })

        def new_file(self, field_name, file_name, content_type, content_length, charset=None):
            pass

        def receive_data_chunk(self, raw_data, start):
            if self.cache_key:
                data = cache.get(self.cache_key)
                data['uploaded'] += self.chunk_size
                cache.set(self.cache_key, data)
            return raw_data

        def file_complete(self, file_size):
            pass

        def upload_complete(self):
            if self.cache_key:
                cache.delete(self.cache_key)

2)Add the UploadProgressCachedHandler to your settings.py file:

from django.conf import global_settings
FILE_UPLOAD_HANDLERS = ('pliks.upload.UploadProgressCachedHandler', ) + \
    global_settings.FILE_UPLOAD_HANDLERS

3)Add code to view.py

    from django.core.cache import cache
    from django.http import HttpResponse, HttpResponseServerError

    def upload_progress(request):
        """
        A view to report back on upload progress.
        Return JSON object with information about the progress of an upload.

        Copied from:
        http://djangosnippets.org/snippets/678/

        See upload.py for file upload handler.
        """
        #import ipdb
        #ipdb.set_trace()
        progress_id = ''
        if 'X-Progress-ID' in request.GET:
            progress_id = request.GET['X-Progress-ID']
        elif 'X-Progress-ID' in request.META:
            progress_id = request.META['X-Progress-ID']
        if progress_id:
            from django.utils import simplejson
            cache_key = "%s_%s" % (request.META['REMOTE_ADDR'], progress_id)
            data = cache.get(cache_key)
            return HttpResponse(simplejson.dumps(data))
        else:
            return HttpResponseServerError(
                'Server Error: You must provide X-Progress-ID header or query param.')

4) Add url

url(r'^admin/upload_progress/$',
    'utils.views.upload_progress',
     name="admin-upload-progress"),

5) In template

   {% block extra-head %}
    <script type="text/javascript" >
    // Generate 32 char random uuid
    function gen_uuid() {
        var uuid = ""
        for (var i=0; i < 32; i++) {
            uuid += Math.floor(Math.random() * 16).toString(16);
        }
        return uuid
    }

    // Add upload progress for multipart forms.
    $(function() {
        /*
        This throws a syntax error...
        $('form[@enctype=multipart/form-data]').submit(function(){
        */
        $('#upload').submit(function(){
            // Prevent multiple submits
            if ($.data(this, 'submitted')) return false;

            var freq = 1000; // freqency of update in ms
            var uuid = gen_uuid(); // id for this upload so we can fetch progress info.
            var progress_url = '/feature/admin/upload_progress/'; // ajax view serving progress info

            // Append X-Progress-ID uuid form action
            this.action += (this.action.indexOf('?') == -1 ? '?' : '&') + 'X-Progress-ID=' + uuid;

            var $progress = $('<div id="upload-progress" class="upload-progress"></div>').
                appendTo(document.body).append('<div class="progress-container"><span class="progress-info">uploading 0%</span><div class="progress-bar"></div></div>');

            // progress bar position
            $progress.css({
                position: ($.browser.msie && $.browser.version < 7 )? 'absolute' : 'fixed',
                left: '50%', marginLeft: 0-($progress.width()/2), bottom: '20%'
            }).show();

            // Update progress bar
            function update_progress_info() {
                $progress.show();
                $.getJSON(progress_url, {'X-Progress-ID': uuid}, function(data, status){
                    if (data) {
                        var progress = parseInt(data.uploaded) / parseInt(data.length);
                        var width = $progress.find('.progress-container').width()
                        var progress_width = width * progress;
                        $progress.find('.progress-bar').width(progress_width);
                        $progress.find('.progress-info').text('uploading ' + parseInt(progress*100) + '%');
                    }
                    window.setTimeout(update_progress_info, freq);
                });
            };
            window.setTimeout(update_progress_info, freq);

            $.data(this, 'submitted', true); // mark form as submitted.
        });
    });
     </script>
    {% endblock %}

    {% block content %}
        <form id='upload' action="." enctype="multipart/form-data" method="POST">
            <table>
                {{ form.as_table }}
            </table>
            <p><input type="submit" value="Submit"></p>
        </form>
    {% endblock %}

Somewhere i got wrong….

  • 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-10T10:44:29+00:00Added an answer on June 10, 2026 at 10:44 am

    You need to provide the class name of the handler, if your file is called UploadProgressCachedHandler.py you are providing the module name here. you would need to use

    FILE_UPLOAD_HANDLERS = ('pliks.upload.UploadProgressCachedHandler.UploadProgressCachedHandler', ) + \
        global_settings.FILE_UPLOAD_HANDLERS
    

    Python convention would be to call the module handlers.py rather than name it after a class it contains.

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

Sidebar

Related Questions

I have an apps and I am making used of django admin, but my
I have a standard Django Admin page that is used to upload multiple files.
I have used httpclient to call a restapi written in django. It returned the
I have java sdk 1.7. I've always used django/python for web development, this will
I have a django app which is used for managing registrations to a survey.
I have used the silverlight control in CRM 2011.It also published on form but
I have used some jquery components in my web site, Suddenly i'm getting an
I have used a plugin that uses prototype js, it's working fine but the
I have used NSSets many times in my apps, but I have never created
I have a Django view that receives POSTs which do not need to have

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.