I'm currently using the drag&drop feature of Primefaces fileUpload component. It works fine, but what I want is to upload files directly by dragging them anywhere into my page, without the need of clicking a button.
I tried this:
$('.dropzone').on({
'dragover dragenter': function (e) {
e.preventDefault();
e.stopPropagation();
},
'drop': function (e) {
var dataTransfer = e.originalEvent.dataTransfer;
if (dataTransfer && dataTransfer.files.length) {
e.preventDefault();
e.stopPropagation();
$.each(dataTransfer.files, function (i, file) {
uploadFile([{"name": "filename", "value": file.name}]);
});
}
}
});
<p:remoteCommand name="uploadFile" action="#{bean.uploadFile()}" />
public void uploadFile(){
String filename =
FacesContext.getCurrentInstance()
.getExternalContext().getRequestParameterMap().get("filename");
}
The problem is that this works for the filename, but not for the file itself. Is this the right approach anyway or is there a way to forward the files
list to Primefaces fileUpload and submit the files programmatically without using the gui-component?