I am facing an issue with image upload in my Phonegap application for iOS. The image upload is not working at times and I am unsure of the exact reason behind this. I am using FormData to upload the image as shown below:
<input id="uploadImage" type="file" name="attachment" onchange="angular.element(this).scope().uploadFile(this.files)"/>
<button type="submit" class="ui-btn ui-btn-b" ng-click="post()"> Upload file</button>
In my JS code, I have the following function that handles the file upload:
$scope.uploadFile = function(files)
{
var fd = new FormData();
//Take the first selected file
fd.append("attachment", files[0]);
$localStorage.fd = fd;
};
$scope.post=function()
{
var fd=$localStorage.fd;
$http.post(httpurl, fd,
{
headers: {'Content-Type': undefined },
transformRequest: angular.identity
})
.success(function (res) {
alert("Image upload successfully");
})
.error(function(res){
alert("Image not uploaded");
})
However, the problem persists as the image upload works inconsistently. I have tried uploading the same image multiple times but faced the same issue each time. Any insights on how to resolve this issue would be greatly appreciated. Thank you.