[英]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,在我的 Phonegap 应用程序中,ios 图像上传有一段时间不起作用,不知道上传的确切原因,这里我将图像上传为 formdata,ex 代码 - 从照片中获取图片,
<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 JS编码- //调用上传文件方法
$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. TLDR:附加在 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.
然后我发现一些 FormData 函数在许多浏览器中不兼容,包括 Safari iOS。
See compatibility list here: https://developer.mozilla.org/en-US/docs/Web/API/FormData在此处查看兼容性列表: 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).我通过将我的字段放在一个表单中,并将整个表单传递为:new FormData(form) 来解决这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.