If have a form with a text field and file upload option. The file is called start.vue(say). From that a module.js(say) file is called. Using that service.js(say) is called. That service.js calls the api in moveController.java(say). I am getting error as: Current request is not a multipart request
Tried to find the syntax so that multipart header is retained till api is called. module.js is getting the appropriate file value. But no idea about service.js
start.vue is:
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script>
export default {
name: "BatchMove",
computed: {
loading() {
return this.$store.state.loader.loading;
},
msgs() {
return this.$store.state.moveBatchHistory.msg;
}
},
components: {},
data() {
return {
file: '',
emailId: ''
};
},
methods: {
submitFile() {
console.log("logging email... " + this.emailId);
const { emailId, file } = this;
this.$store.dispatch("moveBatchHistory/ans", { file, emailId });
},
handleFileUpload(){
this.file = this.$refs.file.files[0];
}
}
}
</script>
module.js is:
import {
moveBatchHistoryService
} from '../_services';
export const moveBatchHistory = {
namespaced: true,
state: {
msg: null
},
actions: {
ans({commit}, {file, emailId}) {
moveBatchHistoryService.getSomething(file, emailId).then(
response => { commit("ans", response); }
);
}
},
mutations: {
ans(state, response) {
state.msg = response
}
}
}
service.js is:
import config from '../config';
import {authHeader} from '../_helpers';
import axios from 'axios';
import {store} from '../_store';
export const moveBatchHistoryService = {
getSomething
};
function getSomething(file, emailId) {
var headers = authHeader();
const requestOptions = {
method: 'POST',
headers: headers,
params: {
"file": file,
"Email": emailId
}
};
return axios(`${config.apiUrl}/api/moveBatch`, requestOptions)
.then(response => {
store.dispatch("alert/errorTime", "We are here!");
return response.data;
}).catch(() => {
store.dispatch("alert/errorTime", "Unable to process your request this time. Please try again latter.");
});
}
'''
moveController.java is:
@RequestMapping(value = "/moveBatch", method = RequestMethod.POST)
public void singleFileUpload(@RequestParam("file") MultipartFile file, String Email) throws Exception {}
current request is not multipart request in moveController.java