我想通過離子1與角1發佈.mp4
文件與一些數據。雖然張貼通過POSTMAN它是好的和工作。我在申請中獲得Success = false
。無法發送文件與角度郵政
在郵差,沒有頭和數據是波紋管, 服務的URL與POST請求http://services.example.com/upload.php 表單數據
j_id = 4124, type = text
q_id = 6, type = text
u_id = 159931, type = text
file = demo.mp4, type = file
在我的應用程序的身體:
$rootScope.uploadQuestion = function() {
var form = new FormData();
form.append("j_id", "4124");
form.append("q_id", "6");
form.append("u_id", "159931");
form.append("file", $rootScope.videoAns.name); //this returns media object which contain all details of recorded video
return $http({
method: 'POST',
headers: { 'Content-Type': 'multipart/form-data' }, // also tried with application/x-www-form-urlencoded
url: 'http://services.example.com/upload.php',
// url: 'http://services.example.com/upload.php?j_id=4124&q_id=8&u_id=159931&file='+$rootScope.videoAns.fullPath,
// data: "j_id=" + encodeURIComponent(4124) + "&q_id=" + encodeURIComponent(8) + "&u_id=" + encodeURIComponent(159931) +"&file=" + encodeURIComponent($rootScope.videoAns),
data: form,
cache: false,
timeout: 300000
}).success(function (data, status, headers, config) {
if (status == '200') {
if (data.success == "true") {
alert('uploading...');
}
}
}).error(function (data, status, headers, config) {
});
}
避免將函數放在'$ rootScope'上。相反,在AngularJS服務中封裝函數。它使代碼更易於測試和維護。有關更多信息,請參閱[AngularJS FAQ - '$ rootScope'存在,但它可以用於邪惡](https://docs.angularjs.org/misc/faq#-rootscope-exists-but-it-can-be - 二手換邪惡)。 – georgeawg
不贊成使用'.success'和'.error'方法。有關更多信息,請參閱[爲什麼不推薦使用角度$ http成功/錯誤方法?從V1.6刪除?](https://stackoverflow.com/questions/35329384/why-are-angular-http-success-error-methods-deprecated-removed-from-v1-6/35331339#35331339)。 – georgeawg