i want to upload image using Angularjs anyone know how do this..REST API wants
Content-Type:multipart/form-data
www.abc.com/images/id
Request Body
{
// --Boundary_1_1626119499_1392398808202
// Content-Type: image/png
// Content-Disposition: form-data; filename="ducky.png"; modification-date="Wed, 05 Nov 2016 19:53:17 GMT"; size=713915; name="upload_image"
// {binary data truncated for display}
}
my Question is how to upload image file using above rest API, how to assign $scope.tempObject = my Upload image Path
$scope.UploadImage = function () {
var config = {headers: {
'Content-Type': 'multipart/form-data'
}
}
$http.post(properties.customerUploadImage_path + "/"+checkprofile,$scope.tempObject,config).success(function (response) {
Console.log('Uploaded');
});
}
I think you don't use
$http
the right way.You can use the
headers
attribute of the$http
service, like this :I suggest you to take a look at the documentation.
Configure the headers with
"Content-Type": undefined
and use the FormData API:Normally the AngularJS $http service uses
Content-Type: application/json
. By settingContent-Type: undefined
, the framework will omit the Content-Type header and the browser will use its default content type which ismultipart/form-data
for FormData objects.Request Header
Request Payload
The DEMO on PLNKR.
For more information see,
AngularJS $http Service API Reference -- Setting HTTP Headers
MDN Documents -- FormData API