Results 1 to 3 of 3

Thread: Extjs 3 python django FileUpload Safari error

  1. #1
    Sencha User
    Join Date
    Dec 2010
    Posts
    4
    Vote Rating
    0
      0  

    Default Extjs 3 python django FileUpload Safari error

    I have a file upload form on a panel and the backend is python with Django web-service.

    This code work FF, IE and Chrome but doesnt work in Safari. The upload request gets processed in the backend but can't parse the fake Json response. Safari gives me a "SyntaxError: Parse error".

    Extjs code:

    var cfg = {
    fileUpload: true,
    frame: false,
    border: false,
    layout: 'form',
    hideLabels: true,
    height: 130,
    labelWidth: 0,
    defaults: {
    allowBlank: false,
    msgTarget: 'side'
    },
    items: [{
    xtype: 'fileuploadfield',
    id: 'form-file',
    itemId: 'form-file',
    width: 300,
    margins: {top:5, right:0, bottom:0, left:0},
    emptyText: 'Attach a SMOP Document',
    name: 'file-path',
    buttonText: '',
    buttonCfg: {
    iconCls: 'upload-icon'
    },
    listeners:{
    fileselected: function(obj, filename){
    this.fireEvent('upload', this, filename);
    }
    }
    }]
    };
    ...
    this.getComponent('form-file').on('upload', this.onUpload, this);
    ...

    onUpload: function() {
    if(this.getForm().isValid()){
    var timestamp = new Date().getTime();
    this.getForm().submit({
    scope: this,
    url: CmCreate.Config.root + '/attach/upload/',
    params: {
    timestamp: timestamp
    },
    success: function(form, action){
    var response = Ext.util.JSON.decode(action.response.responseText);
    this.getComponent('form-file').reset();
    },
    failure: function(form, action){
    var response = Ext.util.JSON.decode(action.response.responseText);
    Ext.Msg.show({
    title: 'Invalid file?',
    msg: response['error'],
    icon: Ext.Msg.ERROR,
    buttons: Ext.Msg.OK
    });
    this.getComponent('form-file').reset();
    }
    });
    }
    }

    Python code: views.py

    file = request.FILES['file-path']
    tempData = file.read()

    if tempData == '':
    response = HttpResponse(simplejson.dumps({'success':False, 'message': 'failure', 'error': 'File is Empty!'}))
    return response

    realName = str(request.POST['timestamp'])
    realName += '_'
    realName += str(file)

    newFile = 'tempFile/'
    newFile += realName

    f = open(str(newFile), 'w')
    f.write(tempData)

    result = {
    "success":True,
    "message": "Success",
    "fileName": str(file),
    "realName": str(newFile)
    }
    json = simplejson.dumps(result, cls=DateTimeAwareJSONEncoder, ensure_ascii=False, indent=4)

    response = HttpResponse(json, mimetype='text/html;')

    return response


    I am stuck on this issue for the last 2 weeks. I have tried all the solution provide online for look alike issue.

    I would really be thankful, if someone could help me with this problem.

    Let me know, if you need clarification or additional info.

  2. #2
    Ext JS Premium Member
    Join Date
    Aug 2009
    Posts
    1
    Vote Rating
    0
      0  

    Default

    This is a strange one, seems to be an issue with your JSON payload. Was able to replicate the issue on my end but changed the JSON payload to not wrap the keys in quotes and everything seems to be working good, here's the django snippet:

    PHP Code:
    json '{success:true, message:"%s", fileName:"%s", realName:"%s"}' % ("Success"str(file), str(newFile)) 
    Hope this is helpful!

  3. #3
    Sencha User
    Join Date
    Dec 2010
    Posts
    4
    Vote Rating
    0
      0  

    Default

    Thank you jkrell. It worked for me.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •