felixrieseberg/React-Dropzone-Component

dataURL is undefined when call in addedfile

Opened this issue · 5 comments

Hi guys

  addedfile= file => {
    console.log(file.dataURL)
}

file.dataURL undefined
How can I get it?

Hi,

I think dataURL is present only image types.

You can get base64 with eventHandler addedFile:

addedfile(file) {
		const addFile = this.props.addFile;

		var reader = new FileReader();
		reader.onload = function(event) {
			addFile({
				nome: file.name,
				base64: event.target.result,
				size: file.size
			});
		};
		reader.readAsDataURL(file);
}

how can i access this data url outside the function
?

I am getting the same undefined accessing dataURL.

NataD commented

Does anyone knows how to access dataURL?

queuecomplete: function () {
$.each(this.files, function (index, file) {
let fileReader = new FileReader();
let base64;
fileReader.onload = (fileLoadedEvent) => {
base64 = fileLoadedEvent.target.result;
file.dataURL = base64;
};
fileReader.readAsDataURL(file);
});
}