I could download files based on id through the API but after download the file doesnt open.
It shows either corrupted or sent as an attachment but same file after downloading from POSTMAN response works.
I am using Pentaho to hit the APIs and javascript below to save file.
Please suggest.
var dir=‘<download_path>’
var fileURL = url;
var url = java.net.URL(fileURL);
var new_filename=mail_message_id+‘‘+id+’’+file_name
//var new_filename=file_name
var httpConn = url.openConnection();
// opens input stream from the HTTP connection
var inputStream = httpConn.getInputStream();
var saveFilePath = dir+new_filename;
var bis = java.io.BufferedInputStream(inputStream);
var bos = java.io.BufferedOutputStream(java.io.FileOutputStream(java.io.File(saveFilePath)));
var inByte;
while((inByte = bis.read()) != -1) {
bos.write(inByte);
}
bis.close();
bos.close();
Hi @sss25
Welcome to the community and thanks for sharing the code snippet. From which endpoint are you obtaining the file URL? Could you please share further details?
Couple of initial thoughts:
When you mention that the file doesn’t open, could it be due to the lack of file extension?
Were you able to inspect the file contents of the one downloaded via Postman vs. via the code snippet? You can test it with a small file with text content for starters.
I was able to open the files. It was not issue with files but the approach of pentaho. Using javascript and saving bytestream was not working, instead parsing it as HTTP response worked. I have DM’d you the snippet.
Now I am having issue at download itself.
Even after using correct API token it gives below response. Is there any way we can download those files.
Hi Sagar, Thanks for sharing the details on what worked. Can you share details on how you access Pipedrive API via Pentaho? I am not familiar with the interface but I can probably help you with the configs Feel free to share the screenshots and logs. Make sure the API token is blurred / hidden
After researching so much I get to know that, if we want to download the files from pipedrive we have to get the first files data from deal/files/ api.
Then we will get the url and name, which we have to pass to file_get_contents.
//save the file by using base name
if(file_put_contents( $file_name,file_get_contents($downloadurl))){
echo “File downloaded successfully!”;
}else{
echo “File downloading failed!”;
}