danielm/uploader

Name of Saved File

Donkeh68 opened this issue · 2 comments

Hi,

Thanks for a great plugin.
I'm using the basic demo version and it's perfect except for one thing: how do I get the name of the file on the server?
I figure I can use the template function to insert it in a data property, but I need help getting the saved name.

Kind regards,
Tim

same here

I managed to resolve this myself, so here are the steps, so as to help anyone else with the same problem:

  1. Create a holder for the file name
  • In the "files-template" section (within your HTML) add the attribute data-filepath="" to the li class="media" element
  1. Send the data to the template function on successful upload
  • In the "demo-config.js" file find the "onUploadSuccess" function
  • replace the line that says ui_multi_update_file_status(id, 'success', 'Upload Complete'); with ui_multi_update_file_status2(id, 'success', 'Upload Complete', JSON.stringify(data));
  1. Populate the template field
  • In the "demo-ui.js" file add the following function:
    function ui_multi_update_file_status2(id, status, message, response) {
    $('#uploaderFile' + id).find('span').html(message).prop('class', 'status text-' + status);
    // EXTRACT SAVED FILE NAME FROM RESPONSE
    var searchString = "files/";
    var indexBegin = response.indexOf(searchString) + searchString.length;
    var lengthResult = response.length - indexBegin - 2;
    var filePath = response.substr(indexBegin, lengthResult);
    // SET VALUE IN TEMPLATE
    $('#uploaderFile' + id).attr("data-filepath", filePath);
    }

Easy when you know how ;)