I have a problem to upload a file with my Struts 2 app.
I have this:
<div class="form-group">
<label for="file">my file</label>
<input type="file" class="form-control-file" name="releveFile" id="file">
</div>
with this function:
const fileUpload= $('#file')[0].files[0];
const formData = new FormData();
formData.append('fileUpload', fileUpload);
$.ajax({
url: '${pageContext.request.contextPath}/projet.releves.upload.action',
type: "POST",
enctype: 'multipart/form-data',
data : formData,
cache: false,
processData: false,
contentType: false,
success: function (data) {
tata.success('', 'Releve créé avec succès');
$('#releveModal').modal('hide');
this.loadReleves();
},
error: function (err) {
tata.error(err);
}
});
my Struts action is:
@Action(value = "projet.releves.upload", results = {
@Result(name = "success", type = "json", params = {"root", "dto"})
}, interceptorRefs = @InterceptorRef(value = "fileUpload", params = {"maximumSize","100000000"}))
public String upload() {
System.out.println("file =" + fileUpload);
System.out.println("file =" + uploadFileName);
return SUCCESS;
}
When I click on upload, I get a 200 and I see my file data in the request. However, the
System.out.println("file =" + fileUpload);
is always file = null
.
Could you help me to fix this?