1

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

4 Answers 4

2

I found a solution without using scriptData. You can pass your data by passing through your URL:

$("#image_upload1").uploadify({
            'method':'POST',
            'buttonText':'Select',
            'fileTypeDesc' : 'Image Files',
            'fileTypeExts' : '*.gif; *.jpg; *.png',
            'swf':'<?php echo base_url()?>resources/flash/uploadify.swf',
            'uploader':'<?php echo site_url('item/update_item_images/'.$picid[0]); ?>',
            'width': 40,
            'multi':false,
            'onUploadComplete':function(file)
            {
                $('.original').hide();
                $('#image1').attr('style','background-image:url("../resources/uploads/<?php echo $id;?>/'+file.name+'");background-size: 140px 119px;');
                $('#hidden_img_value1').attr('value',file.name)
            }
        });

Here I pass the value $picid[0] in uploader. This data you can access in your controller.

Sign up to request clarification or add additional context in comments.

1 Comment

Ingenious. The scriptData thing is always such a pain with uploadify but this totally works around the whole stupid problem. Wish Ronniesan would fix this or write some documentation.
1

@Jimbo after removing inverted comma (') ,then also the value is not reciving in controller.

$("#image_upload1").uploadify({
            'method':'POST',
            'buttonText':'Select',
            'fileTypeDesc' : 'Image Files',
            'fileTypeExts' : '*.gif; *.jpg; *.png',
            'swf':'<?php echo base_url()?>resources/flash/uploadify.swf',
            'uploader':'<?php echo site_url('item/update_item_image1')?>',
            'width': 40,
            'multi':false,
            'scriptData':{id:'<?=$picid[0]?>'},
            'onUploadComplete':function(file)
            {
                //alert(response);
                $('.original').hide();
                $('#image1').attr('style','background-image:url("../resources/uploads/18/'+file.name+'")');
                $('#hidden_img_value1').attr('value',file.name)
            }
        });

1 Comment

i found a solution.we can use formdata for example :- 'formData' : {'someKey':'someValue','someOtherKey' : 1},
0

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?

1 Comment

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

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.