Unable to download file using file download endpoint.

Hello Guys,

I have a portal interface which shows all the documents assigned to a contact in CRM.

I need to create functionality where upon click of a file name the file should get downloaded (like we have browser download).

To achieve this I'm calling sugarCRM file download API

$url = $instance_url . "/DocumentRevisions/{$RevisionId}/file/filename";

File Download:: args :: {"__sugar_url":"v11_1\/DocumentRevisions\/cf17a6b2-e91c-11ea-aa9e-fc3fdbd87f9d\/file\/filename","format":"sugar-html-json","platform":"base\/","module":"DocumentRevisions","record":"cf17a6b2-e91c-11ea-aa9e-fc3fdbd87f9d","field":"filename"}
File Download:: field :: "filename"
File Download:: Bean ID :: "cf17a6b2-e91c-11ea-aa9e-fc3fdbd87f9d"
File Download:: SugarBean ACLFieldAccess :: true
File Download:: def :: {"name":"filename","vname":"LBL_FILENAME","type":"file","dbType":"varchar","required":true,"len":"255","allowEapm":true,"linkModuleOverride":"Documents"}
File Download:: forceDownload :: true
File Download:: api ::
File Download:: download :: {}
File Download:: DownloadFile validateBeanAndField inside IF ::
File Download:: DownloadFile validateBeanAndField def :: {"name":"filename","vname":"LBL_FILENAME","type":"file","dbType":"varchar","required":true,"len":"255","allowEapm":true,"linkModuleOverride":"Documents"}
File Download:: DownloadFile validateBeanAndField info :: {"content-type":"application\/msword","content-length":137728,"name":"180414_Pegasus TDS policy.doc","uri":"","path":"upload:\/\/cf17a6b2-e91c-11ea-aa9e-fc3fdbd87f9d","doc_type":"Sugar"}
File Download:: DownloadFile validateBeanAndField sf :: {"error":null,"hasButton":false,"type":"File"}
File Download:: DownloadFile validateBeanAndField info :: {"content-type":"application\/msword","content-length":137728,"name":"180414_Pegasus TDS policy.doc","uri":"","path":"upload:\/\/cf17a6b2-e91c-11ea-aa9e-fc3fdbd87f9d","doc_type":"Sugar"}
File Download:: DownloadFile validateBeanAndField forceDownload :: true
File Download:: DownloadFile validateBeanAndField header ::
File Download:: DownloadFile validateBeanAndField readfile :: 137728
File Download:: getFile :: null

The API is returning me null as output. Above are the log statements I have added in all the files and functions which manipulate data and return file.

Please any suggestion will be highly appreciated.

Parents
  • Hi ,

    How are you calling the API? If you just want the raw file content, you can try passing force_download=false. If you pass force_download=true, it will pass a Content-Disposition: attachment header, so that the browser can trigger the download, not sure if that's messing up with your API call.

     

    If the user is already logged-in to CRM, and is just clicking a link from your portal, you can also use the download entryPoint

    /index.php?entryPoint=download&id=399a26a8-f436-11ea-9e6e-ac2b6e3c0d93&type=Documents
Reply
  • Hi ,

    How are you calling the API? If you just want the raw file content, you can try passing force_download=false. If you pass force_download=true, it will pass a Content-Disposition: attachment header, so that the browser can trigger the download, not sure if that's messing up with your API call.

     

    If the user is already logged-in to CRM, and is just clicking a link from your portal, you can also use the download entryPoint

    /index.php?entryPoint=download&id=399a26a8-f436-11ea-9e6e-ac2b6e3c0d93&type=Documents
Children
  • It is a separate Portal in a different language. Entrypoint is not a solution.

    We have to use the endpoint. But endpoint is not returning results. below is additional information

    The file download API is returning NULL in the result. I added the logs in MRM API files that are related to the file download functionality. In the very end the API cals getFile() function from wwwroot/include/download_file.php. This function does some processing, until here the data is correct. In the end of the function, it calls outputFile().
    This outputFile() sets the header and downloads the file using Content-Disposition: attachment and obstart() and ob_end_flush();

    I added the logs to print the parameters of the outputFile() and noticed that the function itself is not getting called. So out of curiosity, I moved the code of this function to line where it is called and below are the logs.

    drive.google.com/.../view

    Regards,

    Omair Nalkhande