Elfinder: [js event handler] how to get old file name in rename() event.

Created on 18 May 2017  路  2Comments  路  Source: Studio-42/elFinder

Hi guys. Sorry my english may be insufficient.

var elf = $('#elfinder').elfinder({
                // set your elFinder options here
                <?php if($locale){ ?>
                    lang: '<?= $locale ?>', // locale
                <?php } ?>
                customData: { 
                    _token: '<?= csrf_token() ?>'
                },
                url: '<?= route("elfinder.connector") ?>',  // connector URL
                soundPath: '<?= asset($dir.'/sounds') ?>',
                getFileCallback: function(file) { // editor callback
                    FileBrowserDialogue.mySubmit(file.url); // pass selected file path to TinyMCE
                },
                handlers : {
                    rename : function(event, elfinderInstance) {
                        console.log(event.data.added);
                        console.log(event.data.removed);
                    }
                }
            }).elfinder('instance');
        });

this event hanler console result
added :>

hash: "l1_eWVweWVuaVxhc2Rhc2Rhc2Rhc2QuanBn"
isowner: false
mime: "image/jpeg"
name: "asdasdasdasd.jpg"
phash: "l1_eWVweWVuaQ"
read: 1
size: "735516"
tmb: 1
ts: 1495104014
write: 1

remowed:>

["l1_eWVweWVuaVxhc2Rhc2QuanBn"]

Need old filename and new file name in js.
Is it possible to get this via hash? or selected handle to storage last selected filename and get stored variable in rename event ?

select : function(event, elfinderInstance) {
                        console.log(elfinderInstance.selected());
                    },

output ["l1_eWVweWVuaVxhc2Rhc2Rhc2QuanBn"]

two way allready need decode hash. Sorry look at elfinderInstance i don't seen hash decode or like functions.
I'm use elfinder on tinymce4 / laravel-elfinder package, thanks.

howto

Most helpful comment

@Qh0stM4N Because the path encoding method can be changed with the volume driver, the client side does not implement a function to decode it.

However, if it is the default encoding method, it can be decoded as follows.

var hash = 'l1_RG93bmxvYWRz';
var encPath = hash.substr(hash.indexOf('_')+1);
var path = '/'+atob(encPath.replace(/\-/g, '+').replace(/_/g, '/').replace(/\./g, '='));

All 2 comments

@Qh0stM4N Because the path encoding method can be changed with the volume driver, the client side does not implement a function to decode it.

However, if it is the default encoding method, it can be decoded as follows.

var hash = 'l1_RG93bmxvYWRz';
var encPath = hash.substr(hash.indexOf('_')+1);
var path = '/'+atob(encPath.replace(/\-/g, '+').replace(/_/g, '/').replace(/\./g, '='));

@nao-pon H谋mm okay 谋 understand why it is not possible on the client side.

var hash = 'l1_RG93bmxvYWRz';
var encPath = hash.substr(hash.indexOf('_')+1);
var path = '/'+atob(encPath.replace(/-/g, '+').replace(/_/g, '/').replace(/./g, '='));

_Thanks you that decoding will helpfull for me._

Was this page helpful?
0 / 5 - 0 ratings