Package models

Examples of models.Attachment


        if (uploader.isAnonymous()) {
            return forbidden();
        }

        // Attach the file to the user who upload it.
        Attachment attach = new Attachment();
        boolean isCreated = attach.store(file, filePart.getFilename(), uploader.asResource());

        // The request has been fulfilled and resulted in a new resource being
        // created. The newly created resource can be referenced by the URI(s)
        // returned in the entity of the response, with the most specific URI
        // for the resource given by a Location header field.
View Full Code Here


            return ok(responseBody);
        }
    }

    public static Result getFile(Long id) throws IOException {
        Attachment attachment = Attachment.find.byId(id);
        String action = HttpUtil.getFirstValueFromQuery(request().queryString(), "action");
        String dispositionType = StringUtils.equals(action, "download") ? "attachment" : "inline";

        if (attachment == null) {
            return notFound("The file does not exist.");
        }

        String eTag = "\"" + attachment.hash + "-" + dispositionType + "\"";

        if (!AccessControl.isAllowed(UserApp.currentUser(), attachment.asResource(), Operation.READ)) {
            return forbidden("You have no permission to get the file.");
        }

        response().setHeader("Cache-Control", "private, max-age=3600");

        String ifNoneMatchValue = request().getHeader("If-None-Match");
        if(ifNoneMatchValue != null && ifNoneMatchValue.equals(eTag)) {
            response().setHeader("ETag", eTag);
            return status(NOT_MODIFIED);
        }

        File file = attachment.getFile();

        if(file != null && !file.exists()){
            Logger.error("Attachment ID:" + id + " (" + file.getAbsolutePath() + ") does not exist on storage");
            return internalServerError("The file does not exist");
        }
View Full Code Here

                .equals("delete")) {
            return badRequest("_method must be 'delete'.");
        }

        // Remove the attachment.
        Attachment attach = Attachment.find.byId(id);
        if (attach == null) {
            return notFound();
        }

        if (!AccessControl.isAllowed(UserApp.currentUser(), attach.asResource(), Operation.DELETE)) {
            return forbidden();
        }

        attach.delete();

        logIfOriginFileIsNotValid(attach.hash);

        if (Attachment.fileExists(attach.hash)) {
            return ok("The attachment is removed successfully, but its origin file still exists.");
View Full Code Here

TOP

Related Classes of models.Attachment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.