tags:

views:

2574

answers:

4

Hi, I'm having problems with scriptData on uploadify, I'm pretty sure the config syntax is fine but whatever I do, scriptData is not passed to the upload script.

I tested in both FF and Chrome with flash v. Shockwave Flash 9.0 r31

This is the config:

    $(document).ready(function() {
    $('#id_file').uploadify({
        'uploader'          : '/media/filebrowser/uploadify/uploadify.swf',
        'script'            : '/admin/filebrowser/upload_file/',
        'scriptData'        : {'session_key': 'e1b552afde044bdd188ad51af40cfa8e'},
        'checkScript'       : '/admin/filebrowser/check_file/',
        'cancelImg'         : '/media/filebrowser/uploadify/cancel.png',
        'auto'              : false,
        'folder'            : '',
        'multi'             : true,
        'fileDesc'          : '*.html;*.py;*.js;*.css;*.jpg;*.jpeg;*.gif;*.png;*.tif;*.tiff;*.mp3;*.mp4;*.wav;*.aiff;*.midi;*.m4p;*.mov;*.wmv;*.mpeg;*.mpg;*.avi;*.rm;*.pdf;*.doc;*.rtf;*.txt;*.xls;*.csv;',
        'fileExt'           : '*.html;*.py;*.js;*.css;*.jpg;*.jpeg;*.gif;*.png;*.tif;*.tiff;*.mp3;*.mp4;*.wav;*.aiff;*.midi;*.m4p;*.mov;*.wmv;*.mpeg;*.mpg;*.avi;*.rm;*.pdf;*.doc;*.rtf;*.txt;*.xls;*.csv;',
        'sizeLimit'         : 10485760,
        'scriptAccess'      : 'sameDomain',
        'queueSizeLimit'    : 50,
        'simUploadLimit'    : 1,
        'width'             : 300,
        'height'            : 30,
        'hideButton'        : false,
        'wmode'             : 'transparent',
        translations        : {
                              browseButton: 'BROWSE',
                              error: 'An Error occured',
                              completed: 'Completed',
                              replaceFile: 'Do you want to replace the file',
                              unitKb: 'KB',
                              unitMb: 'MB'
        }
    });
    $('input:submit').click(function(){
        $('#id_file').uploadifyUpload();
        return false;
    });
});

I checked that other values (file name) are passed correctly but session_key is not.

This is the decorator code from django-filebrowser, you can see it checks for request.POST.get('session_key'), the problem is that request.POST is empty.

def flash_login_required(function):
    """
    Decorator to recognize a user  by its session.
    Used for Flash-Uploading.
    """

    def decorator(request, *args, **kwargs):
        try:
            engine = __import__(settings.SESSION_ENGINE, {}, {}, [''])
        except:
            import django.contrib.sessions.backends.db
            engine = django.contrib.sessions.backends.db
        print request.POST
        session_data = engine.SessionStore(request.POST.get('session_key'))
        user_id = session_data['_auth_user_id']
        # will return 404 if the session ID does not resolve to a valid user
        request.user = get_object_or_404(User, pk=user_id)
        return function(request, *args, **kwargs)
    return decorator
A: 

Can you post the server side upload script that you are using?

Nick Knowlson
Thanks for your comment, I don't think the server side script is relevant, since I checked what get sent to the server.I'm using django filebrowser, which checks the user session_key parameter through a decorator function, this function fails because there's nothing in request.POSTI added the decorator code.
elpaso66
Well that makes things difficult, everything looks right to me; I did essentially the same thing (different language) and it worked alright. I hope you are able to get this resolved, sorry I have no suggestions. :)
Nick Knowlson
A: 

This might sound silly, but are you sure it's a session_key problem?

I had an authentication problem with filebrowser+uploadify but the problem was not the session_key but that the site was protected by a HTTP digest authentication set in Apache and, although session_key was sent fine, uploadify does not send the HTTP authentication headers.

Is your web server requiring any form of authentication?

No, it uses the standard django authentication for the admin panel (cookie based).
elpaso66
A: 

Does anyone knows?

My web server requiring auth, while uploading a file i've got window with auth. Even if I'll put username and pass application is crashed.

vanyamtv
A: 

I had a a similar problem passing script data in the past. Removing the inverted comma (') around the key in the key/value pairs fixed my problem

Instead of:

'scriptData'        : {'session_key': 'e1b552afde044bdd188ad51af40cfa8e'}, 

Use:

'scriptData'        : {session_key: 'e1b552afde044bdd188ad51af40cfa8e'}, 

(useful Uploadify post here)

Jimbo