如何使用AngularJS发布二进制文件(使用上传DEMO)
我试图.mp4
通过带有角度1的离子1 发布带有一些数据的文件。虽然通过POSTMAN发布它很好并且正常工作。我正在Success = false
申请。
在POSTMAN中,没有标题和数据如下, 表单数据中带有POST请求的服务URL 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) { });}
相关分类