This topic contains 2 replies, has 2 voices, and was last updated by  Duo_Liang 2 weeks, 5 days ago.

  • Author
    Posts
  • Participant
    sethuramanraji
    Newbie
    Member since: 04.07.2018
    Number of posts: 9

    Hi All,
    When I’m consuming the attachment requirements download API and PDF Document download API, It just gives me the stream of data. Is there anyway, that I can get the MIME type of that particular Document/Attachment?.

    Thanks in Advance.

    Keymaster
    Duo_Liang
    Guru
    Member since: 14.06.2018
    Number of posts: 290

    Score

    0

    Hi Sethuraman,

    If you are downloading attachment by GET /api/packages/{packageId}/attachment/{attachmentId}, you will receive the attachment(s) with the original MIME type.
    The response content-type is application/octet-streamand you just need to store file name with the corresponding extension type or directly open the API url in your browser. Attachment 1 is a screenshot of response OSS will send back to you when you call this API.
    I also created some snippet for you to download the attachment in REST method in Java in attachment 2.
    If you are using GET /api/packages/{packageId}/attachment/zip, the MIME type will be application/zip, and when you unzip the file, attachment(s) will be in original type.

    BTW, the types allowed to upload as an attachment are: PDF, DOC, DOCX, RTF, ODT, JPG, JPEG, PNG, BMP, TXT, XLS, XLSX.

    And for the documents in your transaction, I think they can only be downloaded with PDF type as all audit trails have to be sealed into the PDF that’s why it can’t be downloaded as the original type. Even if you are using GET /packages/{packageId}/documents/{documentId}/original, the file will still be in PDF type.

    Hope this could help you!
    Duo


    Duo Liang
    OneSpan Junior Technical Evangelist
    • This reply was modified 2 weeks, 5 days ago by  Duo_Liang.
    • This reply was modified 2 weeks, 5 days ago by  Duo_Liang.
    Attachments:
    You must be logged in to view attached files.
    Keymaster
    Duo_Liang
    Guru
    Member since: 14.06.2018
    Number of posts: 290

    Score

    0

    And the code snippet here.

    public class DownloadAttachment {
    	private String API_KEY = "your api key";
    	private String url = "https://sandbox.esignlive.com/api/packages/";
    	
    	// https://sandbox.esignlive.com/a/api/packages/7YuopfUIcfnrP47mBs_M8sHNzrQ=/attachment/2BBmP9p5ctMB
    		public void downloadAttachment(String packageId, String docId) throws IOException {
    			URL client = new URL(url + packageId + "/attachment/" + docId);
    			HttpURLConnection conn = (HttpURLConnection) client.openConnection();
    			conn.setRequestProperty("Authorization", "Basic " + API_KEY);
    
    			String contentDisposition = ((HttpURLConnection) conn).getHeaderField("content-disposition");
    			String fileName = contentDisposition.substring(contentDisposition.lastIndexOf("filename=\"") + 10,
    					contentDisposition.length() - 1);
    			InputStream inputStream = conn.getInputStream();
    			inputStream = conn.getInputStream();
    			String saveFilePath = "C:\\Users\\I5-PC-HDMI\\Documents\\docs\\" + fileName;
    			FileOutputStream outputStream = new FileOutputStream(saveFilePath);
    
    			int bytesRead = -1;
    			byte[] buffer = new byte[4096];
    			while ((bytesRead = inputStream.read(buffer)) != -1) {
    				outputStream.write(buffer, 0, bytesRead);
    			}
    
    			outputStream.close();
    			inputStream.close();
    			conn.disconnect();
    		}
    
    		public static void main(String[] args) throws Exception {
    			new DownloadAttachment().downloadAttachment("7YuopfUIcfnrP47mBs_M8sHNzrQ=", "2BBmP9p5ctMB");
    		}
    }

    Duo Liang
    OneSpan Junior Technical Evangelist
    • This reply was modified 2 weeks, 5 days ago by  Duo_Liang.

You must be logged in to reply to this topic.