0

How to convert file object to dataURL in javascript?

My HTML code is

<input id="FileUpload" type="file" name="files[]" class="filestyle" data-input="false"
    data-buttonText="Add Files" data-badge="false" data-buttonName="btn-primary"onclick="validateFiles() "

    data-url="rest/ses/${eVO.id}/esultFile.json" multiple >

JavaScript Code:

function validateFiles() {
var prodVisible = $('#caseFileProductionTab').is(':visible');
var fileObj = document.getElementById('caseResultFileUpload');

fileObj.url=""rest/ses/${eVO.id}/esultFile.json?prodVisible="+prodVisible  ;

        }

I want to redirect on data-url + extra parameter like prodVisible on server. but in javascript i am unable to get value of data-url. Can anyone help me ?

1 Answers1

0

Inside your validateFiles function you can access your attribute like this:

document.getElementById("FileUpload").getAttribute("data-url");
Saravana
  • 37,852
  • 18
  • 100
  • 108
  • getting proper but How can i redirect at data-url after adding extra parameter ? –  Mar 07 '16 at 16:16
  • When do you want to redirect? On clicking of the file input or after the file has been uploaded? – Saravana Mar 07 '16 at 16:18
  • after select file i want to redirect –  Mar 07 '16 at 16:20
  • You can attach to the `onchange` event instead of `onclick` as described here http://stackoverflow.com/a/5942858/2419531. But don't you want to save the file before redirecting? – Saravana Mar 07 '16 at 16:28
  • I am redirecting on window.location = fileObjectUrl+productionfile; but not getting value of productionfile on server –  Mar 07 '16 at 16:38