2016-10-01 31 views
1

在我的Phonegap應用程序中ios圖片上傳不能正常工作一段時間,不知道上傳的確切原因, 這裏我已經上傳圖像爲formdata, ex代碼 - 爲了從照片畫面,Phonegap ios圖像上傳爲formdata不起作用,

<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上傳文件的方法

$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"); 
}) 

現在的問題是,圖像上傳一段不知道實際是起訴。我試圖發佈相同的圖片上傳,但它反映了同樣的問題。 請分享您的反饋,以解決我的問題。 在此先感謝。

回答

4

TLDR:Append在Safari iOS中不起作用。

我有一個類似的問題困擾了我幾天。 然後我發現一些FormData函數在許多瀏覽器中都不兼容,包括Safari iOS。

見兼容列表:新FORMDATA(形式): https://developer.mozilla.org/en-US/docs/Web/API/FormData

我通過在一個形式我的領域,並通過整個形式,圍繞這一問題得到。

+0

謝謝。花了我幾天 - 我以爲這是一個奇怪的錯誤與aurelia,我從來沒有得到一個錯誤或任何有用的。 – Nukey