I’m unable to upload a image to my server using Cordova’s file and file-transfer plugin through ionic. I need, and make a valid request to the server endpoint that’s expecting my image along with other data, but when I make the request, my payload is sent is as empty, which causes the server to respond with a 500 and ultimately an “error code 3” from the cordova plugin.
I’ve looked around and tried to figure this out, but seem to be stuck. Any help would be appreciated. I’ve tried this on Android
Here’s a snippet of my FileTransfer related code:
$scope.uploadFile = function() {
var params = {};
//var url = encodeURI(“http://192.168.1.7:8080/ServerFileTransfer/upload.php”);
var url = encodeURI(“https://www.imedilane.com/wapi/med.svc/shyamu”);
//var url = “https://www.imedilane.com/serverupload.aspx”;
//target path may be local or url
var targetPath = "https://www.imedilane.com/src/assets/video/Dr-chowdhary.png";
var filename = targetPath.split("/").pop();
var option;
option = new FileUploadOptions();
options = {
fileKey: "file",
fileName: filename,
chunkedMode: false,
mimeType: "image/png",
httpMethod:"POST",
headers : {
Connection:"close"
}
};
$cordovaFileTransfer.upload(url, targetPath, options).then(function(result) {
console.log("SUCCESS: " + JSON.stringify(result.response));
alert("success");
alert(JSON.stringify(result.response));
}, function(err) {
console.log("ERROR: " + JSON.stringify(err));
alert(JSON.stringify(err));
}, function (progress) {
// constant progress updates
$timeout(function () {
$scope.downloadProgress = (progress.loaded / progress.total) * 100;
})
});
}
})