Question
Bank Of America
IN
Last activity: 11 Nov 2016 14:03 EST
How we can extract a attacment in a directory on server from blob.
Hi have a requirement in which i have to extacrt the attachment from blob and store the attachemnt in a directory in server.
Is there any way in pega to do that?
I have tried using tools.sendfile method but this method will show a pop uu to download the attachemnt and extact the docuemnt in service export directory.
***Updated by Moderator: Marissa. Removed user added #helpme and Ask the Expert group tags. Apologies for confusion, shouldn't have been an end-user option***
-
Like (0)
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Virtusa IT Consulting
AE
you can write an activity with java step and probably can use code similar to below
// queries the database
String sql = "SELECT * FROM pc_data_workattach WHERE pxattachname="+"\'"+FileName+"\'";
/*"+"\'"+"praxis2-1.6.2.jar"+"\'"+";"; */ /*"+"\'"+FileName+"\'";*/
oLog.debug(sql);
java.sql.PreparedStatement statement = conn.prepareStatement(sql);
//statement.setInt(1, FileName);
java.sql.ResultSet result = statement.executeQuery();
if (result.next()) {
String fileName = result.getString("pxattachname");
java.sql.Blob blob = result.getBlob("pzpvstream");
java.io.InputStream inputStream = blob.getBinaryStream();
int fileLength = inputStream.available();
//ParseState parseState = (ParseState) tools.getStepPage().getObject("pyParseState");
//java.io.InputStream is = parseState.getInputStream();
byte[] buffer = new byte[inputStream.available()];
inputStream.read(buffer);
java.io.File targetFile = new java.io.File(FileLocation+"\\"+fileName);
java.io.OutputStream outStream = new java.io.FileOutputStream(targetFile);
outStream.write(buffer);
inputStream.close();
outStream.close();
Bank Of America
IN
I am not trying to dowload the complete blob but only the attachment inside the blob.
Pegasystems Inc.
GB
Also: instead of 'sendFile' - consider using the Engine Class 'PRFile' to write to the server's 'ServiceRequest' directory (etc).
There is an example here of writing (a generated QR code Image) a file on the server: https://collaborate.pega.com/question/how-can-i-put-qr-code-print-reportexpexcel-or-pdf
In your case: I *think* you might have to perform an extra step to decode base64->raw bytes - check the PRPC Engine Javadocs (Designer Studio > Resources > Engine API) for 'Base64Util'
Cheers
John
Bank Of America
IN
Hi John,
I have used 'BASE64Util' to decode the attachemnt stream but it is working fine for only text file.The function is uanble to decode the PDF,EXCEL,WORD files.
When decodded PDF,EXCEL and word file and open it in my system then i got a messege that the file is corrupted .
Pegasystems Inc.
GB
Suggestion: Try writing the file data out without using Base64Util - and then examining the contents of the file with a text editor - if you are able to share this - please attach the file to the post here and we can take a look.
Bank Of America
IN
Hi,
I tried to write the file without decoding it to base 64 into a text file.
But after opening the file in NOTEPAD++ ,I can see the content of file is in Binary form(like- JVBERioXLQKsJKDKNgdtb5NM86wk...).
Because of restrictions i can not share the file.
Just a info that when i used the send file method i am getting the proper fie and there are no issue when i was tried to open that file.The issue with that method is that it save's file in servie export directory but i want to save my file into a specific directory.
BlueCross BlueShield of NC
US
please try these steps :
1) Open the attachment object(Data-work-attach-File)
2) Using connect File method store it on the location specified on the connect file rule.
Pegasystems Inc.
GB
But you want binary files right ? WORD , EXCEL are (usually, not necessarily) a Binary Format ?
You sure the file extension isn't just wrong here ?
Accenture Services
US
Not sure you got the solution for this or not. If not, attached is the one. Attached is the screenshot from 5.5. But its the same technique in 7.x as well.
Jave step,
You can have DSS value prefixed to the filename to have the generic path instead of hard coding.
java.io.OutputStream stream = new java.io.FileOutputStream("<FileName with complete path>");