ucStoreAttachment

Purpose

Applies To

Attachment Methods

Signature

public Attachment ucStoreAttachment(
                             Attachment attachment) 

Notes

Example

public Attachment ucStoreAttachment(Attachment attach) { // session object

        String attachId = attach.getAttachmentId();
        String problemId = String.valueOf(attach.getProblemId());

        String zeros = "00000000";

        String zeroId = zeros.substring(problemId.length()) + problemId;

        String millions = zeroId.substring(0, 2);
        String thousands = zeroId.substring(2, 5);
        String rootDir = "";
        rootDir = Z.config.getConfigValue("ATTACHMENT_ROOT_DIR");
       
        if (rootDir == null) {
            rootDir = System.getProperty("java.io.tmpdir");
        }
        String attachDir = rootDir + "/" + millions + "/" + thousands + "/" + 
                              problemId + "/" + attachId;
        String fileName = attach.getFileName();

        try {
            File inputFile = attach.getTempFile();
            File outputDir = null;
            File outputFile = null;
            long filesize = inputFile.length();

            boolean status = false;

            outputDir = new File(attachDir);
            // Create the output directory
            if (!outputDir.exists()) {
                outputDir.mkdirs();
            }
            if (outputDir.exists()) {
                outputFile = new File(attachDir, fileName);
            }
            Z.log.writeToLog(Z.log.INFO, "THE File is : " + outputFile.getAbsolutePath());
            if (inputFile != null && outputFile != null) {
                status = this.copyFile(inputFile, outputFile);
            }
            if (status) {
                attach.setExternalAttachmentIdent(outputFile.getAbsolutePath());
                attach.setStoredInExternalSystem(true);
                attach.setToBeStoredInternal(false);
                attach.setStoredLocal("N");
            }
        }
        catch (Exception e) {
            ErrorWriter.write(e, ErrorWriter.LOG);
        }
        return attach;
    }