Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
154
rated 0 times [  159] [ 5]  / answers: 1 / hits: 8036  / 10 Years ago, wed, november 19, 2014, 12:00:00

I am trying to make a HTTP request using $resource, that will send the same information this postman request does.



Here is the request I need to replicate:



Postman request:



enter



Postman Headers:



enter



index.html



<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<meta name=viewport content=initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width>
<title>File Upload</title>

<link href=lib/ionic/css/ionic.css rel=stylesheet>
<link href=css/style.css rel=stylesheet>

<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href=css/ionic.app.css rel=stylesheet>
-->

<!-- ionic/angularjs js -->
<script src=lib/ionic/js/ionic.bundle.js></script>

<!-- cordova script (this will be a 404 during development) -->
<script src=cordova.js></script>

<!-- your app's js -->
<script src=js/app.js></script>
<script src=js/controllers.js></script>
<script src=libionicjsangular-file.js></script>
<script src=libionicjsangular-resource.js></script>
</head>
<body ng-app=starter ng-controller=FileController>
<input type=file ng-model=model.image change=upload(model)/>
</body>
</html>


controllers.js



angular.module('starter.controllers',[])

.controller('FileController', function ($scope, $resource) {
var Files = $resource('http://api.artistappz.com/api/v1/cover/x-app-id/3865f620590f40d493ec8d900b4c24d3/', null, {
post: {
method:'POST'
}
});

angular.extend($scope, {

model: { image: null },

upload: function(model) {
console.log(File chosen);
console.log(model);
Files.prototype.$post.call({},model.image, function(self, headers) {
// Handle server response
console.log(DONE);
});
}
});
});


Headers from my request: i . stack . imgur . com/4inXR.jpg


More From » angularjs

 Answers
5

In one of my project I use this angular module https://github.com/danialfarid/angular-file-upload.
It works for me very well, also there is demo site.


[#41156] Tuesday, November 18, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dewayneh

Total Points: 538
Total Questions: 114
Total Answers: 97

Location: Liberia
Member since Fri, Oct 22, 2021
3 Years ago
;