AnsweredAssumed Answered

PDF won't download with app.api.fileDownload

Question asked by Francesca Shiekh on May 17, 2016
Latest reply on May 18, 2016 by Francesca Shiekh

I have a custom API that generates a PDF file, the file is stored in the cache correctly and I can see it in my browser when go to the URL if I reload after I get there, which is puzzling. (https://<mysugarcrm>/cache/Sugarpdf/Contract_1463529577.pdf ) but I can't get the file to force download.

I am using app.api.fileDownload to get the file to automatically download as I do for another custom API where I generate a .zip but it's not working.


From the API

          $cachefile = sugar_cached('Sugarpdf/').$filename;
          $fp = sugar_fopen($cachefile, 'w');
          fwrite($fp, $this->pdf);


This same kind of call works just fine in another custom API that zips a set of files from a Documents module together and downloads the zip. So why is it not working for the single pdf file? There are no errors in the logs (PHP, Sugar) and the Console shows:

Resource interpreted as Document but transferred with MIME type application/pdf


The call is from a custom field definition the menu for which is built dynamically from pdfManager similar to pdfaction


    _triggerDownload: function(url) {
      var self = this;'GET', url, null, {
           success: function(o){
           error: function (e){
             app.error.handleHttpError(e, {});

     startDownload: function(uri) {
       app.api.fileDownload(uri, {
         error: function(data) {
           app.error.handleHttpError(data, {});
       }, {iframe: this.$el});