Reputation: 145
In my Phonegap application ios image upload is not working for some time, don't know the exact reason for uploading, Here I have upload the image as formdata, ex code - To get the picture from photos,
<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>
JS Coding- //CALLS UPLOAD FILE METHOD
$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");
})
Now the issue is, image is uploading sometime and not know the actual issue. I have tried to post the same image upload but it's reflects same issue. Please share your feedback to fix my issue. Thanks in advance.
Upvotes: 1
Views: 1339
Reputation: 349
TLDR: Append doesn't work in Safari iOS.
I've had a similar issue puzzle me for days. Then I discovered that some FormData functions are not compatible in many browsers, including Safari iOS.
See compatibility list here: https://developer.mozilla.org/en-US/docs/Web/API/FormData
I got around the issue by having my fields in a form, and passing the entire form as: new FormData(form).
Upvotes: 4