0๐
โ
I solved it the only thing I was doing wrong is that I was passing the name of file with its uri, we only need to pass the uri in fileChooser.open() function. I will post the client side code. Here is the solution :-
SOLVED CLIENT CODE
<template>
<div><br>
<hr><br><br>
<v-btn color="warning" @click="selectFiles()">Upload Files</v-btn>
</div>
</template>
<script>
export default {
data() {
return {
}
},
mounted() {
document.addEventListener("deviceready", onDeviceReady , false);
function onDeviceReady() {
console.log(window.FileTransfer);
}
},
methods: {
selectFiles() {
window.fileChooser.open((file) => {
this.upload(file.uri);
})
},
upload(fileURL) {
var options = new window.FileUploadOptions();
options.fileKey = "image";
options.httpMethod = 'POST';
options.fileName = fileURL.substr(fileURL.lastIndexOf('/') + 1);
options.mimeType = "image/jpeg";
var ft = new window.FileTransfer();
ft.upload(fileURL, encodeURI("http://192.168.1.111:8000/user/fileUpload"), (r)=>
{
alert("uploaded successfully..")
console.log("Code = " + r.responseCode);
console.log("Response = " + r.response);
console.log("Sent = " + r.bytesSent);}, (error)=>{
alert(JSON.stringify(error));
console.log("upload error source " + error.source);
console.log("upload error target " + error.target);
}, options);
}
}
}
</script>
Source:stackexchange.com