Skip to content

Instantly share code, notes, and snippets.

@ocReaper
Created December 18, 2015 22:21
Show Gist options
  • Save ocReaper/b320f6e67dbeabd27b89 to your computer and use it in GitHub Desktop.
Save ocReaper/b320f6e67dbeabd27b89 to your computer and use it in GitHub Desktop.
Blob file download in Angular.js using $resource Part 2
/* global Blob */
(function () {
'use strict';
angular
.module('app')
.factory('Email', Email);
function Email($resource) {
var url = 'emails/'
, EmailBase
, xlsxContentType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
EmailBase = $resource(url + ':emailId', {emailId: '@id'}, {
getFile: {
method: 'GET',
url: url + ':emailId/files/:fileName',
params: {
emailId: '@id',
fileName: '@fileName'
},
headers: {
accept: xlsxContentType
},
responseType: 'arraybuffer',
cache: false,
transformResponse: function (data) {
return {
response: new Blob([data], {type: xlsxContentType})
};
}
}
});
return EmailBase;
}
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment