简体   繁体   中英

Phonegap ios image upload as formdata not working,

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.

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM