ucViewAttachment

Purpose

This exit is used to view the contents of file attachments stored within the ExtraView database, on the filesystem, or within an external repository linked to ExtraView

Applies To

Attachment Methods

Signature

public boolean ucViewAttachment(
                      ServletOutputStream out,
                      Attachment attachment) 

Notes

There is a ucViewDocument exit which is used to view the contents of fields with a display type of document and image.

Example

    public boolean ucViewAttachment(ServletOutputStream out, Attachment attach) {
        Z.log.writeToLog(Z.log.DEBUG1, "View Attachment  : ");

        boolean status = false;
        int count = 0;
        long bytesRead = 0l;

        FileInputStream is = null;
        BufferedInputStream bis = null;

        BufferedOutputStream bos = null;
        File input = new File(attach.getExternalAttachmentIdent());
        long fileSize =  input.length();
        try {
            // Get the input stream of the Blob
            is = new FileInputStream(input);
            bis = new BufferedInputStream(is);

            bos = new BufferedOutputStream(out);

            byte[] bytes = new byte[1024];

            // Read the blob 1024 bytes at a time
            while ( (count = bis.read(bytes)) > 0) {
                // Write the bytes out to the response
                if (bos != null)
                    bos.write(bytes, 0, count);
                bytesRead = bytesRead + count;
            }
            if (fileSize == bytesRead)
                status = true;
        }
        catch (Exception e) {
            ErrorWriter.write(e, ErrorWriter.LOGERR);
        }
        finally {
            try {
                if (bis != null)
                    bis.close();
            }
            catch (Exception e) {}
            try {
                if (bos != null)
                    bos.close();
            }
            catch (Exception e) {}
        }
        return true;
    }