Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. [HttpGet]
  2.  
  3. public async Task<IHttpActionResult> Download(Guid customDocId)
  4. {
  5.  
  6. byte[] responseContent = await Task.FromResult(FileNetApiClientFactory.Get(customDocId).DownloadDocument(customDocId, "pdf", true));
  7. HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK)
  8. {
  9. Content = new ByteArrayContent(responseContent),
  10. StatusCode = HttpStatusCode.OK,
  11. };
  12. response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = string.Concat(customDocId.ToString(), ".pdf") };
  13. response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
  14. return ResponseMessage(response);
  15.  
  16. }
  17.  
  18. //saveAs method is from FileSaver.js
  19. vm.download = function () {
  20. documentService.download($scope.customDocumentId).then(function (fileData) {
  21. var blob = new Blob([fileData], { type: 'application/pdf' });
  22. saveAs(blob, $scope.customDocumentId + ".pdf");
  23. }).catch(function () {
  24.  
  25. });
  26. }
  27.  
  28. function _download(customDocumentId) {
  29. return Restangular
  30. .one('customdocument', customDocumentId).one('download')
  31. .get(null, { responseType: 'arraybuffer' });
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement