AngularJs download excel - angularjs

I'm trying to download an excel file from server in angularjs but I'm getting rare characters when I try to generate a blob.
Here is my server response (an array of bytes):
[-48,-49,17,-32,-95,-79,26,-31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,59,0,3,0,-2,-1,9,0,6,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,16,0,0,7,0,0,0,1,0,0,0,-2,-1,-1,-1,0,0,0,0,8,0,0,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,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,0,0,47,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,8,16,0,0,6,5,0,-45,16,-52,7,65,0,0,0,6,0,0,0,-31,0,2,0,-80,4,-63,0,2,0,0,0,-30,0,0,0,92,0,112,0,7,0,0,114,111,100,114,105,103,111,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,66,0,2,0,-80,4,97,1,2,0,0,0,61,1,2,0,0,0,-100,0,2,0,14,0,25,0,2,0,0,0,18,0,2,0,0,0,19,0,2,0,0,0,-81,1,2,0,0,0,-68,1,2,0,0,0,61,0,18,0,104,1,14,1,92,58,-66,35,56,0,0,0,0,0,1,0,88,2,64,0,2,0,0,0,-115,0,2,0,0,0,34,0,2,0,0,0,14,0,2,0,1,0,-73,1,2,0,0,0,-38,0,2,0,0,0,49,0,21,0,-56,0,0,0,-1,127,-112,1,0,0,0,0,0,0,5,0,65,114,105,97,108,49,0,21,0,-56,0,0,0,-1,127,-112,1,0,0,0,0,0,0,5,0,65,114,105,97,108,49,0,21,0,-56,0,0,0,-1,127,-112,1,0,0,0,0,0,0,5,0,65,114,105,97,108,49,0,21,0,-56,0,0,0,-1,127,-112,1,0,0,0,0,0,0,5,0,65,114,105,97,108,30,4,26,0,5,0,21,0,0,34,36,34,35,44,35,35,48,95,41,59,40,34,36,34,35,44,35,35,48,41,30,4,31,0,6,0,26,0,0,34,36,34,35,44,35,35,48,95,41,59,91,82,101,100,93,40,34,36,34,35,44,35,35,48,41,30,4,32,0,7,0,27,0,0,34,36,34,35,44,35,35,48,46,48,48,95,41,59,40,34,36,34,35,44,35,35,48,46,48,48,41,30,4,37,0,8,0,32,0,0,34,36,34,35,44,35,35,48,46,48,48,95,41,59,91,82,101,100,93,40,34,36,34,35,44,35,35,48,46,48,48,41,30,4,44,0,42,0,39,0,0,95,40,42,32,35,44,35,35,48,95,41,59,95,40,42,32,40,35,44,35,35,48,41,59,95,40,42,32,34,45,34,95,41,59,95,40,64,95,41,30,4,53,0,41,0,48,0,0,95,40,34,36,34,42,32,35,44,35,35,48,95,41,59,95,40,34,36,34,42,32,40,35,44,35,35,48,41,59,95,40,34,36,34,42,32,34,45,34,95,41,59,95,40,64,95,41,30,4,61,0,44,0,56,0,0,95,40,34,36,34,42,32,35,44,35,35,48,46,48,48,95,41,59,95,40,34,36,34,42,32,40,35,44,35,35,48,46,48,48,41,59,95,40,34,36,34,42,32,34,45,34,63,63,95,41,59,95,40,64,95,41,30,4,52,0,43,0,47,0,0,95,40,42,32,35,44,35,35,48,46,48,48,95,41,59,95,40,42,32,40,35,44,35,35,48,46,48,48,41,59,95,40,42,32,34,45,34,63,63,95,41,59,95,40,64,95,41,-32,0,20,0,0,0,0,0,-11,-1,32,0,0,0,0,0,0,0,0,0,0,0,-64,32,-32,0,20,0,1,0,0,0,-11,-1,32,0,0,-12,0,0,0,0,0,0,0,0,-64,32,-32,0,20,0,1,0,0,0,-11,-1,32,0,0,-12,0,0,0,0,0,0,0,0,-64,32,-32,0,20,0,2,0,0,0,-11,-1,32,0,0,-12,0,0,0,0,0,0,0,0,-64,32,-32,0,20,0,2,0,0,0,-11,-1,32,0,0,-12,0,0,0,0,0,0,0,0,-64,32,-32,0,20,0,0,0,0,0,-11,-1,32,0,0,-12,0,0,0,0,0,0,0,0,-64,32,-32,0,20,0,0,0,0,0,-11,-1,32,0,0,-12,0,0,0,0,0,0,0,0,-64,32,-32,0,20,0,0,0,0,0,-11,-1,32,0,0,-12,0,0,0,0,0,0,0,0,-64,32,-32,0,20,0,0,0,0,0,-11,-1,32,0,0,-12,0,0,0,0,0,0,0,0,-64,32,-32,0,20,0,0,0,0,0,-11,-1,32,0,0,-12,0,0,0,0,0,0,0,0,-64,32,-32,0,20,0,0,0,0,0,-11,-1,32,0,0,-12,0,0,0,0,0,0,0,0,-64,32,-32,0,20,0,0,0,0,0,-11,-1,32,0,0,-12,0,0,0,0,0,0,0,0,-64,32,-32,0,20,0,0,0,0,0,-11,-1,32,0,0,-12,0,0,0,0,0,0,0,0,-64,32,-32,0,20,0,0,0,0,0,-11,-1,32,0,0,-12,0,0,0,0,0,0,0,0,-64,32,-32,0,20,0,0,0,0,0,-11,-1,32,0,0,-12,0,0,0,0,0,0,0,0,-64,32,-32,0,20,0,0,0,0,0,1,0,32,0,0,0,0,0,0,0,0,0,0,0,-64,32,-32,0,20,0,1,0,43,0,-11,-1,32,0,0,-8,0,0,0,0,0,0,0,0,-64,32,-32,0,20,0,1,0,41,0,-11,-1,32,0,0,-8,0,0,0,0,0,0,0,0,-64,32,-32,0,20,0,1,0,44,0,-11,-1,32,0,0,-8,0,0,0,0,0,0,0,0,-64,32,-32,0,20,0,1,0,42,0,-11,-1,32,0,0,-8,0,0,0,0,0,0,0,0,-64,32,-32,0,20,0,1,0,9,0,-11,-1,32,0,0,-8,0,0,0,0,0,0,0,0,-64,32,-109,2,4,0,16,-128,3,-1,-109,2,4,0,17,-128,6,-1,-109,2,4,0,18,-128,4,-1,-109,2,4,0,19,-128,7,-1,-109,2,4,0,0,-128,0,-1,-109,2,4,0,20,-128,5,-1,96,1,2,0,0,0,-123,0,39,0,30,7,0,0,0,0,31,0,99,117,101,115,116,105,111,110,97,114,105,111,95,53,53,52,57,56,99,97,99,48,48,97,51,100,101,98,48,100,102,-116,0,4,0,1,0,1,0,-82,1,4,0,1,0,1,4,23,0,8,0,1,0,0,0,0,0,0,0,-4,0,-105,1,34,0,0,0,34,0,0,0,15,0,0,78,111,109,98,114,101,32,112,97,99,105,101,110,116,101,26,0,0,84,46,32,105,100,101,110,116,105,102,105,99,97,99,105,-13,110,32,112,97,99,105,101,110,116,101,6,0,0,73,80,83,83,45,52,6,0,0,73,80,83,83,45,49,12,0,0,67,117,101,115,116,105,111,110,97,114,105,111,6,0,0,73,80,83,83,45,51,6,0,0,73,80,83,83,45,50,23,0,0,73,100,101,110,116,105,102,105,99,97,99,105,-13,110,32,112,97,99,105,101,110,116,101,6,0,0,73,80,83,83,45,56,2,0,0,73,68,6,0,0,78,-6,109,101,114,111,28,0,0,73,80,83,83,95,85,82,73,78,65,82,89,95,81,85,65,76,73,84,89,95,79,70,95,76,73,70,69,10,0,0,73,80,83,83,95,83,67,79,82,69,17,0,0,70,101,99,104,97,32,100,101,32,115,111,108,117,99,105,-13,110,6,0,0,73,80,83,83,45,54,6,0,0,73,80,83,83,45,55,6,0,0,73,80,83,83,45,53,1,0,0,53,24,0,0,53,53,52,57,56,99,97,99,48,48,97,51,100,101,98,48,100,102,100,98,50,100,98,57,1,0,0,54,2,0,0,49,48,1,0,0,48,4,0,0,73,80,83,83,12,0,0,79,99,99,97,115,105,111,110,97,108,108,121,5,0,0,49,50,49,50,50,1,0,0,49,12,0,0,49,32,116,111,32,54,32,116,105,109,101,115,1,0,0,50,11,0,0,51,32,77,97,121,44,32,50,48,49,53,1,0,0,56,16,0,0,77,111,115,116,32,111,102,32,116,104,101,32,116,105,109,101,3,0,0,79,110,101,14,0,0,114,111,100,114,105,103,111,32,99,97,114,100,105,111,1,0,0,55,-1,0,42,0,8,0,93,5,0,0,12,0,0,0,-39,5,0,0,-120,0,0,0,66,6,0,0,-15,0,0,0,-115,6,0,0,60,1,0,0,-41,6,0,0,-122,1,0,0,10,0,0,0,9,8,16,0,0,6,16,0,-69,13,-52,7,-63,0,0,0,6,0,0,0,11,2,20,0,0,0,0,0,1,0,0,0,3,0,0,0,0,0,0,0,-10,9,0,0,13,0,2,0,1,0,12,0,2,0,100,0,15,0,2,0,1,0,17,0,2,0,0,0,16,0,8,0,-4,-87,-15,-46,77,98,80,63,95,0,2,0,1,0,42,0,2,0,0,0,43,0,2,0,0,0,-126,0,2,0,1,0,-128,0,8,0,0,0,0,0,0,0,0,0,37,2,4,0,0,0,-1,0,-127,0,2,0,-63,4,20,0,0,0,21,0,0,0,-125,0,2,0,0,0,-124,0,2,0,0,0,-95,0,34,0,1,0,100,0,1,0,1,0,1,0,2,0,44,1,44,1,0,0,0,0,0,0,-32,63,0,0,0,0,0,0,-32,63,1,0,85,0,2,0,8,0,0,2,14,0,0,0,0,0,3,0,0,0,0,0,17,0,0,0,8,2,16,0,1,0,0,0,17,0,-1,0,0,0,0,0,64,1,15,0,8,2,16,0,2,0,0,0,17,0,-1,0,0,0,0,0,64,1,15,0,-3,0,10,0,1,0,0,0,15,0,10,0,0,0,-3,0,10,0,1,0,1,0,15,0,9,0,0,0,-3,0,10,0,1,0,2,0,15,0,4,0,0,0,-3,0,10,0,1,0,3,0,15,0,13,0,0,0,-3,0,10,0,1,0,4,0,15,0,1,0,0,0,-3,0,10,0,1,0,5,0,15,0,7,0,0,0,-3,0,10,0,1,0,6,0,15,0,0,0,0,0,-3,0,10,0,1,0,7,0,15,0,3,0,0,0,-3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-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1]
and its headers:
Access-Control-Allow-Headers → Content-Type, jwt
Access-Control-Allow-Methods → POST, GET, PUT, DELETE
Access-Control-Allow-Origin → *
Content-Disposition → attachment; filename=questionnaire_55498cac00a3deb0dfdb2db9.xls
Content-Length → 13723
Content-Type → application/vnd.ms-excel; charset=UTF-8
Date → Thu, 07 May 2015 08:40:48 GMT
Last-Modified → Thu, 07 May 2015 08:40:48 GMT
Server → spray-can/1.3.2
In my angularjs application i have something like:
// HttpService
downloadRequest: function (url, handledStatuses) {
var hs = handledStatuses || [];
var deferred = $q.defer();
$http.get(url, {responseType: 'arraybuffer', handledStatuses: hs})
.success(function (data, status, headers, config) {
deferred.resolve(data);
})
.error(function (error, status, headers, config) {
deferred.reject(error);
});
return deferred.promise;
}
// Download Service
getQuestionnaireReport: function (questionnaireId) {
return HttpManager.downloadRequest(UrlManager.getReportsUrl() + 'questionnaires/' + questionnaireId);
}
// Download manager
downloadFile: function (bytes, name, extension, type) {
if (this.detectIE() === false) {
var urlCreator = window.URL || window.webkitURL || window.mozURL || window.msURL;
var link = document.createElement("a");
if ("download" in link) {
var blob = new Blob([bytes], {type: type});
var url = urlCreator.createObjectURL(blob);
link.setAttribute("href", url);
link.setAttribute("download", name + '.' + extension);
var event = document.createEvent('MouseEvents');
event.initMouseEvent('click', true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
link.dispatchEvent(event);
}
}
else {
window.navigator.msSaveOrOpenBlob(new Blob([bytes], {type: type}), name + '.' + extension);
}
},
// In my controller
$scope.downloadQuestionnaireReport = function (questionnaireId) {
$scope.downloadPr = DoctorServices.getQuestionnaireReport(questionnaireId);
$scope.downloadPr.then(
function (response) {
DownloadsManager.downloadFile(response, 'questionnaire_' + questionnaireId, 'xls', 'application/octet-stream');
}
);
return $scope.downloadPr;
};
I have already tried with different kind of content types and responseTypes, my problem is that I'm getting bizarre characters when I try to open the downloaded file like so:
Am I missing something?
Thank you all very much in advance.

after some hours looking for a solution to this problem, I realized that my problem was in the response marshaller I was using.
At the moment I'm using spray.io as my rest services provider and for my json responses I'm using Json4s library. In this question, my server response is not correct, so the solution I found was to remove Json4s marshaller for this specific service; then all worked as expected.

Related

Downloaded document getting corrupted using Blob method in angularJS

Downloading a file used to work fine in my application until I upgraded Angular to the latest. Even now, the file is getting downloaded, but the issue is that it is getting corrupted. Upload file is working fine and if we check in the file server, the file will be intact. But upon download, I am getting corrupted file.
Html :
<td data-title="''">
<a tooltip="Download CV" ng-hide="!talent.resumePath" tooltip-trigger tooltip-animation="false" tooltip-placement="bottom" ng-click="downloadResume(talent.id)" data-placement="top" data-toggle="tooltip" data-original-title="resume">
<img src="../../img/DownloadIcon.png" /></a>
</td>
Controller :
downloadResume: function(employeeId) {
return apiServices.getFileFromTalentPool('/talentpool/resume?id=' + employeeId)
},
Where, getFileFromTalentPool is : https://hastebin.com/yivaterozi.js
Endpoint :
public FileResult GetResume(int id) {
var result = _services.GetResume(id);
if (result != null) {
HttpContext.Response.ContentType = result.ContentType;
HttpContext.Response.Headers["Access-Control-Expose-Headers"] = "FileName";
HttpContext.Response.Headers["FileName"] = result.FileDownloadName;
}
return result;
}
Usually I download Doc files. I tried with a notepad file to see if it's the same. Strangely, I noticed that I am able to open the notepad file, but its content is manipulated to something like [object Object]. But for Doc files, it just shows:
How can I fix this?
it looks like the code at https://hastebin.com/yivaterozi.js was updated from using deprecated $http.success() method to current $http.then(). Promise' success callback function (within then method) receives only one object argument: https://docs.angularjs.org/api/ng/service/$http. Deprecated 'success' method got more arguments (data, status, headers) and data already contained raw data. When using then(), data is located under data property of response, so try to change your $http call to:
$http({
method: 'GET',
cache: false,
url: fileurl,
responseType:'arraybuffer',
headers: {
'Authorization': "Bearer " + $rootScope.userInfo.access_token,
'Access-Control-Allow-Origin': '*'
}
}).then(function (data) {
var octetStreamMime = 'application/octet-stream';
var success = false;
// Get the headers
var headers = data.headers();
...
...
please note that headers are fetched correct here from the data object and not from the third argument (just add var, since we removed empty arguments).
Now in each place that you use data, change it to data.data, like:
// Try using msSaveBlob if supported
var blob = new Blob([data.data], { type: contentType });
or just change argument data to response and add var data = response.data; anf modify headers getter to headers = response.headers();:
$http({
method: 'GET',
cache: false,
url: fileurl,
responseType:'arraybuffer',
headers: {
'Authorization': "Bearer " + $rootScope.userInfo.access_token,
'Access-Control-Allow-Origin': '*'
}
}).then(function (response) {
var octetStreamMime = 'application/octet-stream';
var success = false;
// Get data
var data = response.data;
// Get the headers
var headers = response.headers();
...
...

Uploading images using Angularjs

I have this code for image uploading:
$scope.uploadAvatar = function(e) {
$scope.uploadAvatarError = false;
$scope.uploadAvatarSuccess = false;
var f = document.getElementById('uploadAvatar').files[0],
fd = new FormData();
if (!f) {
return
}
fd.append('user', $scope.user.user_email);
fd.append('photo', f);
$http.post(apiUrl + 'addProfilePicture', fd, {
transformRequest: angular.identity,
headers: {'Content-Type': undefined}
}).then(function(response){
console.log(response);
})
}
When I send it to server, it returns status 200, but nothing is uploaded.
In network tab in chrome dev tools it says
ContentType application/json instead of multipart/form-data.
How can I change that?
You can use the very thorough angular-file-upload module to achieve that.
If I may, you can even add the preview with this module, which can be useful / nice in case of avatars.

S3 putObject fails using aws-sdk

It's driving me crazy, any help would be much appreciated!
To set up my bucket in S3 I followed http://www.cheynewallace.com/uploading-to-s3-with-angularjs/
Regarding this post I made following "improvements" by extended the policy with a wildcard and giving more rights
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:DeleteObject",
"s3:DeleteObjectVersion",
"s3:GetObject",
"s3:GetObjectAcl",
"s3:GetObjectTorrent",
"s3:GetObjectVersion",
"s3:GetObjectVersionAcl",
"s3:GetObjectVersionTorrent",
"s3:PutObject",
"s3:PutObjectAcl",
"s3:PutObjectVersionAcl"
],
"Resource": [
"arn:aws:s3:::photos-eu/*"
]
}
]
}
and added < ExposeHeader>ETag< /ExposeHeader > to the Cors settings of the bucket
Then my angular service using the aws-sdk look like
/// <reference path="../../../typings/tsd.d.ts" />
module Services {
export interface IS3UploadService {
upload(imgName:string, imgData:string):ng.IPromise<{}>;
}
export class S3UploadService implements IS3UploadService {
static $inject = ['$q'];
private bucket:AWS.S3;
constructor(private $q:ng.IQService) {
var credentials = new AWS.Credentials("myAccessKeyId", "mySecretAccessKey");
AWS.config.update(credentials);
AWS.config.region = "eu-west-1";
this.bucket = new AWS.S3({params: {Bucket: 'peterparker-photos-eu', maxRetries: 10, region: "eu-west-1"}});
}
upload(imgName:string, imgData:string):ng.IPromise<{}> {
var deferred = this.$q.defer();
var params:AWS.s3.PutObjectRequest = {
Bucket: "peterparker-photos-eu",
Key: imgName,
Body: imgData,
ContentType: "image/jpeg",
ContentEncoding: "Base64"
};
this.bucket.putObject(params, (err:any, data:any) => {
if (err) {
console.error("->" + JSON.stringify(err));
deferred.reject(err);
} else {
console.info(data);
deferred.resolve(data);
}
});
return deferred.promise;
}
}
}
angular.module('App')
.service('S3UploadService', Services.S3UploadService);
For my test purpose, I push in the imgData an img encoded as Base64, something like "/9j/4AAQSkZJRgABAgAAZABkA...." (of course a valid image converted with http://base64-image.de)
And as result, each time I try, I've got following error
{"line":25,"column":24996,"sourceURL":"http://localhost:8100/lib/aws-sdk/dist/aws-sdk.min.js","message":"The request signature we calculated does not match the signature you provided. Check your key and signing method.","code":"SignatureDoesNotMatch","region":null,"time":"2016-06-08T15:12:09.945Z","requestId":null,"statusCode":403,"retryable":false,"retryDelay":60.59883770067245}
So much fun...
Update headers:
General
Request URL:https://peterparker-photos-eu.s3-eu-west-1.amazonaws.com/1465408512724.jpg
Request Method:PUT
Status Code:403 Forbidden
Remote Address:54.231.131.16:443
Response headers
Access-Control-Allow-Methods:HEAD, GET, PUT, POST, DELETE
Access-Control-Allow-Origin:*
Access-Control-Expose-Headers:ETag, x-amz-meta-custom-header
Connection:close
Content-Type:application/xml
Date:Wed, 08 Jun 2016 17:55:20 GMT
Server:AmazonS3
Transfer-Encoding:chunked
Vary:Origin, Access-Control-Request-Headers, Access-Control-Request- Method
x-amz-id-...
x-amz-request-id:...
Request Headers
Accept:*/*
Accept-Encoding:gzip, deflate, sdch, br
Accept-Language:fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4,de;q=0.2
Authorization:AWS ...
Connection:keep-alive
Content-Encoding:Base64
Content-Length:38780
Content-MD5:...
Content-Type:image/jpeg; charset=UTF-8
Host:peterparker-photos-eu.s3-eu-west-1.amazonaws.com
Origin:http://localhost:8100
Referer:http://localhost:8100/?ionicplatform=ios
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36
X-Amz-Date:Wed, 08 Jun 2016 17:55:20 GMT
X-Amz-User-Agent:aws-sdk-js/2.3.18
Request payload
Img base64 code
Update
Even by trying to upload a non Base64 content it finish with the same error
var paramsHtml:AWS.s3.PutObjectRequest = {
Bucket: "peterparker-photos-eu",
Key: "HelloWorld.html",
Body: "The Body",
ContentType: "text/html"
};
Update #2
I moved to a solution with a signed URL generated by my node js server as described in following solution, still got the same error as result...but I least I try ;)
upload file from angularjs directly to amazon s3 using signed url
Freak I finally find the solution or at least a solution.
After migrating my client aws-sdk based solution to a solution where the server generate a signedUrl I was still facing the same error. Short story long, it fixed the problem by setting in both side the Content-type for the header.
My code if someone face the same problem one day:
Server Node.js
var AWS = require('aws-sdk');
AWS.config.update({accessKeyId: "myKey", secretAccessKey: "mySecret"});
AWS.config.region = 'eu-west-1';
app.post('/api/images', securityPolicy.authorise, function (req, res) {
var s3 = new AWS.S3();
var imgName = req.body.imgName;
var contentType = req.body.contentType;
// Expires in seconds
var params = {Bucket: 'photos-eu', Key: imgName, Expires: 600, ContentType: contentType};
s3.getSignedUrl('putObject', params, function (err, url) {
if (err) {
res.status(500).json({
error: "Presigned S3 url for putObject can't be created. " + JSON.stringify(err)
});
} else {
res.json({url: url});
}
});
});
Client angular:
First or course there is the part to call the node server, obvious POST to my server
And then the second part processing the signedURL
private uploadToS3(preSignedUrl:string, imgData:string):ng.IPromise<{}> {
var deferred = this.$q.defer();
// Post image to S3
this.$http({
method: 'PUT',
url: preSignedUrl,
headers: {'Content-Type': 'image/jpeg'},
data: imgData
})
.then((response:any) => {
console.log("Image uploaded to S3" + JSON.stringify(response));
deferred.resolve();
}, (response:any) => {
console.log("Error Presigned URL" + JSON.stringify(response));
deferred.reject(response);
});
return deferred.promise;
}

AngularJS Stalled Requests to REST API

I have an AngularJS (1.4) app that relies upon $http.get requests to a REST API.
There are two types of request, one for "Search Results", and one for "View Profile". Sometimes (but not consistently so), the request for "View Profile" is not returned. Checking in the Chrome network tab it's marked as Stalled.
Looking this up it seems maybe I am hitting the Chrome max connections limit - but I don't understand how this can be the case as surely the "connection" is not created again each time an $http.get request is called?
Does anybody have any ideas?
Simplified code below:
app.factory('garageService', function($http,$q) {
var garageService = {};
var url = ''; // CAN'T SHARE
var token = ''; // CAN'T SHARE
var radius = 50;
// GET SEARCH RESULTS
garageService.getList = function(lat,lng) {
var deferred = $q.defer();
if(window.XDomainRequest){
//XDR Version for IE
} else {
$http.get(url+'/'+token+'/list/'+lat+'/'+lng+'/'+radius, { cache: true, timeout: 10000 }).success(function(response){
deferred.resolve(response);
}).error(function(){
deferred.reject();
});
}
return deferred.promise;
}
// GET VIEW PROFILE
garageService.getProfile = function(id) {
var deferred = $q.defer();
if(window.XDomainRequest){
//XDR Version for IE
} else {
$http.get(url+'/'+token+'/get/'+id, { cache: true, timeout: 10000 }).success(function(response){
deferred.resolve(response);
}).error(function(){
deferred.reject();
});
}
return deferred.promise;
}
return garageService;
});
And here are the response headers from a working request:
Access-Control-Allow-Credentials:true
Access-Control-Allow-Origin: //CAN'T SHARE
Cache-Control:no-cache, must-revalidate, post-check=0, pre-check=0
Connection:Keep-Alive
Content-Type:application/json
Date:Thu, 31 Dec 2015 10:28:37 GMT
ETag:"1451557717"
Expires:Sun, 19 Nov 1978 05:00:00 GMT
Keep-Alive:timeout=2, max=200
Last-Modified:Thu, 31 Dec 2015 10:28:37 GMT
Server:Apache
Transfer-Encoding:chunked
X-Powered-By:PHP/5.3.3

Download a zip file in AngularJS

Trying to have a zip file download in AngularJS I looked at AngularJS: download pdf file from the server and coded my controller as:
RolloutService.export(rollout.id, function(data, status, headers) {
var headers = headers();
var filename = headers['download-filename'] || 'file';
var octetStreamMime = 'application/octet-stream';
var contentType = headers['Content-Type'] || octetStreamMime;
if (navigator.msSaveBlob) {
var blob = new Blob([data], { type: contentType });
navigator.msSaveBlob(blob, filename);
} else {
var urlCreator = window.URL || window.webkitURL || window.mozURL || window.msURL;
if (urlCreator) {
var link = document.createElement("a");
if ("download" in link) {
var blob = new Blob([data], { type: contentType });
var url = urlCreator.createObjectURL(blob);
link.setAttribute("href", url);
link.setAttribute("download", filename);
var event = document.createEvent('MouseEvents');
event.initMouseEvent('click', true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
link.dispatchEvent(event);
} else {
var blob = new Blob([data], { type: octetStreamMime });
var url = urlCreator.createObjectURL(blob);
window.location = url;
}
}
}
});
But my file comes partly only.
Trying to unzip it gives:
stephane#stephane-ThinkPad-X60:~> unzip -l file
Archive: file
error [file]: missing 96319383 bytes in zipfile
(attempting to process anyway)
error [file]: start of central directory not found;
zipfile corrupt.
Note that if skipping the controller and going for a direct window.open() then the file comes complete and can be unzipped.
On the controller export request, the browser console shows the following headers:
Remote Address:127.0.0.1:8080
Request URL:http://localhost:8080/nitro-project-rest/rollouts/2/export
Request Method:GET
Status Code:200 OK
Request Headersview source
Accept:application/json, text/plain, */*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en
Authorization:Basic bnNuQG5zbi5jb206ZXRvaWxl
Connection:keep-alive
Host:localhost:8080
Origin:http://localhost:9000
Referer:http://localhost:9000/
User-Agent:Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/34.0.1847.116 Chrome/34.0.1847.116 Safari/537.36
Response Headers
Access-Control-Allow-Headers:Accept-Language,Content-Type,X-Requested-With,accept,Origin,Access-Control-Request-Method,Access-Control-Request-Headers,Authorization
Access-Control-Allow-Methods:POST, PUT, GET, OPTIONS, DELETE
Access-Control-Allow-Origin:http://localhost:9000
Access-Control-Max-Age:3600
Cache-Control:no-store
Cache-Control:no-cache
Content-Disposition:attachment; filename="Orange-rollout-rollout-export.zip"
Content-Length:1960
Content-Type:application/zip
Date:Wed, 05 Nov 2014 20:33:31 GMT
download-filename:Orange-rollout-rollout-export.zip
Expires:Thu, 01 Jan 1970 00:00:00 GMT
Pragma:no-cache
Server:Apache-Coyote/1.1
X-Content-Type-Options:nosniff
X-Frame-Options:DENY
X-XSS-Protection:1; mode=block
My $http service was corrupting the file when sending the request.
I needed to add the following configuration:
responseType: 'arraybuffer'
as in:
factory.rolloutExport = function(rolloutId, successCallback, failureCallback) {
$http({
url: ENV.NITRO_PROJECT_REST_URL + '/rollouts/' + rolloutId + '/export',
method: 'GET',
responseType: 'arraybuffer',
cache: false,
headers: {
'Content-Type': 'application/json; charset=utf-8',
'Authorization': AuthService.getCredentialsHeaders()
}
}).success(successCallback).error(failureCallback);
};
Now the zip file comes back untouched by any encoding converter.

Resources