Hi all
I have a webpage that displays my sugar cases to the end user. this pae also lists notes and not attachments for the user to download. However I am having issues with getting sugar to download the file.
when the download link is click it goes to a download.php file to initialise the download and passes the query vars of the file endpoint
Fullscreen
1
2
3
4
5
// [content-type] => application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
// [content-length] => 59349
// [name] => Copy of Countries by region.xlsx
// [uri] => rest/v11/Note/2fe82a46-0efe-11eb-9221-080027633d6c/file/filename
// [doc_type] =>
following https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_10.0/Cookbook/Web_Services/REST_API/PHP/How_to_Manipulate_File_Attachments/ i create a curlrequest to get the file however this does not initioate the download
Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$tokens = MagiConnect_SugarCRM::testConn(); // gets the oauth token for testing
$curl = curl_init('http://mc.sugarcrm10.mac/rest/v11/CAtts_Case_Attachments/2fe82a46-0efe-11eb-9221-080027633d6c/file/uploadfile');
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
"OAuth-Token: {$tokens->access_token}",
)
);
$response = curl_exec($curl);
// echo "";
// print_r($response);
// echo "";
$header_size = curl_getinfo($curl,CURLINFO_HEADER_SIZE);
$headers = substr($response, 0, $header_size);
$file = substr($response, $header_size);
this did not initialise the download so i replaced put_file content with force download headers in download.php
Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$tokens = MagiConnect_SugarCRM::testConn(); // gets the oauth token for testing
$curl = curl_init('http://mc.sugarcrm10.mac/rest/v11/CAtts_Case_Attachments/2fe82a46-0efe-11eb-9221-080027633d6c/file/uploadfile');
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
"OAuth-Token: {$tokens->access_token}",
)
);
$response = curl_exec($curl);
// echo "";
// print_r($response);
/// echo "";
$header_size = curl_getinfo($curl,CURLINFO_HEADER_SIZE);
$headers = substr($response, 0, $header_size);
$file = substr($response, $header_size);
this downloads a corrupt file. Can anyone help me on how i get my download button to download the requested file from sugar?sugar does seem to be returning the correct response in the curl request