Retrieves an attached file from the specified field of the table record in your knowledgebase.
ew.EWRetrieveAttachedAsSOAPAttachment(String sessionId, String tableName, long id, String fieldName, int position); |
Use the EWRetrieveAttachedAsSOAPAttachment call to retrieve an attached file from a File or Image field in the table record.
When retrieving attached files, consider the following rules and guidelines:
Retrieving files from records involves the following basic steps:
In MyKB knowledgebase as user A, retrieve the first file named B.txt currently attached in the field Additional Files of case #456 in the current directory.
The task is completed by performing the following steps:
You can generate sample Web Services code for any table by selecting Setup > Tables > (Edit Table) > API > Download Sample.
public int retrieve() throws Exception { EWServiceAPI binding = new EWServiceAPIServiceLocator().getDemo(); try { String sessionId = binding.EWLogin("MyKB", "A", "password", "en"); WSCase wsCase = (WSCase) binding.EWRead(sessionId, "case", 456); String[] fileNames = wsCase.getAdditional_Files(); int n = 0; if (fileNames!=null) { for (int i = 0; i < files.length; i++) { if ("B.txt".equals(fileNames[i])) { binding.EWRetrieveAttachedAsSOAPAttachment("case", 456, "additional_files", i); Object[] attachments = binding.getAttachments(); AttachmentPart attachmentPart = (AttachmentPart) attachments[0]; final InputStream inputStream = attachmentPart.getDataHandler().getInputStream(); BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("B.txt")); int b; while ((b = inputStream.read()) != -1) bos.write(b); bos.flush(); bos.close(); break; } } } return; } finally { binding.EWLogout(sessionId); } } |
Name | Type | Description |
---|---|---|
sessionId | String | Session token. |
tableName | String | The name of the table where the record is. |
id | long | The identifier of the record to attach the files to. |
fieldName | String | The name of the field to attach the files to. |
position | int | The position of the file to be retrieved. |
The file as a SOAP attachment.
EWSessionException - client not logged in or the session has expired; client should re-login.
EWPermissionException - user used to create the session lacks the sufficient privileges to read the record.
EWWrongDataException - client has supplied the wrong data, for instance ID cannot be found.
EWOperationException - the operation has been blocked by an function, for example a table-level lock.
EWIntegrityException - the specified table cannot be found or its primary key cannot be identified.
EWUnexpectedException - an unexpected exception has happened; user should report this for investigation.
Related articles |