How to change the url property of Ext.ux.upload.Button

758 views Asked by At

I'm using this upload plugin: https://github.com/harrydeluxe/extjs-ux#extuxuploadbutton

And I want to change "url" property. Tell me please how it is possible?

I tried doing this but it doesn't work:

UploadObject.uploader.url = '/newUrl.php?ObjId=1'; 


Ext.Loader.setConfig({
    enabled: true,
    paths: {
        'Ext.ux': 'http://extjs.cachefly.net/extjs-4.1.1-gpl/examples/ux/',
        'Ext.ux.upload': '../../ux/upload'
    }
});

Ext.require(['Ext.grid.*',
        'Ext.data.*',
        'Ext.util.*',
        'Ext.state.*',
        'Ext.ux.upload.Button',
        'Ext.ux.upload.plugin.Window']);

Ext.onReady(function() {
UploadObject = Ext.create('Ext.ux.upload.Button', {
    renderTo: Ext.getBody(),
    text: 'Select files',
    //singleFile: true,
    plugins: [{
                  ptype: 'ux.upload.window',
                  title: 'Upload',
                  width: 320,
                  height: 350
              }
    ],
    uploader: 
    {
        url: '/1/getimages.php?ObjectId=',
        uploadpath: '/Root/files',
        autoStart: false,
        max_file_size: '2020mb',            
    //...
    }
//...
});
1

There are 1 answers

3
Guilherme Lopes On BEST ANSWER

This UX uses the plupload plugin to upload the files, unfortunately, it does not provide a quick method for you to replace the upload url.

First, create a reference to your Upload Button, can be create like this if you have only one uploader: var uploadButton = Ext.ComponentQuery.query('uploadbutton')[0];

the reference to the plupload plugin will be inside uploader.uploader so run this:

var uploadButton = Ext.ComponentQuery.query('uploadbutton')[0],
    uploader = uploadButton.uploader.uploader;   
uploader.settings.url = '/newUrl.php?ObjId=1';

If you want to keep your code, thats fine, just make sure you add the var before creating UploadObject.

var UploadObject = Ext.create('Ext.ux.upload.Button', {
    renderTo: Ext.getBody(),
    text: 'Select files',
    //singleFile: true,
    plugins: [{
        ptype: 'ux.upload.window',
        title: 'Upload',
        width: 320,
        height: 350
    }],
    uploader: {
        url: '/1/getimages.php?ObjectId=',
        uploadpath: '/Root/files',
        autoStart: false,
        max_file_size: '2020mb',
    //...
    }
//...
});

UploadObject.uploader.uploader.settings.url = '/newUrl.php?ObjId=1';