<input type="file" ng-model="articleimg" placeholder="upload related img">
$http.post($scope.base_url+'create.php',
{params {view:'view',articleimg:$scope.articleimg}})
.then(function(response){
console.log(response);
});
I would like to know how and where to specify the content-type: multipart/form-data in this angularjs post request?
Please assist. the default seems to be "application/json, text/plain," which does not work with the image/file uploads.
if(isset($_FILES['articleimg'])===true ){
echo "sucessfull";
}else echo "unsuccessfull";
the code above alway echos unsuccessfull.
$http.post shortcut method in angular takes three parameters, url, request data and a config object in which you can set headers like below :
In your case it will be :
You can also construct the request object like below :
and then make the request like this :
If you want to set common application wide headers , you can use default headers which will be added to all the requests by default like below :
This will add the above mentioned content type for all the requests.
More information in the documentation here