Jello framework

Attachment field

  • @Attachment (jello.annotation.Attachment)
    Mark the field as an Attachment field which will refer to a document stored in the Blobstore. The field value will hold the blob id and must be of a type String. You can specify the file type (optional) and it will be enforced by the server.

    @Expose @Attachment
    String attachmentField;
    
    @Expose @Attachment(accept="image/png")
    String photo1;
    	
    @Expose @Attachment(accept="image/*")
    String photo2;
    
    Jello manages the entire lifecycle of the attachment as follow:

  • - Get upload URL
    Before you can upload an attachment, you need to obtain a valid upload URL. This URL is associated with a specific element field on a JEllo entity and will remain valid for a short period of time, typically less then 10 minutes.

    Getting upload URL for an attachment field on a new instance:
    /jello/upload/NS/Entity/element

    Getting upload URL for an attachment field on ane existing instance:
    /jello/upload/NS/Entity(id)/element

    Response:
    { "d" : {"uploadUrl" : "the-upload-URL"}}

    - Uploading an attachment
    To creat a custom upload form, the form must include a file upload field, and the form's enctype must be set to multipart/form-data. You can use the field metadata to specify the ecpected field's type:

    { ...
       fields: [
          { name: "photo", type: "jello.Attachment(image/*)" },
          ...
       ]
    }
    

    refer to the Entity Metadata chapter to read more about the metadata response format)

    In addition, Jello Form provides a special attachment control for attachment fields with built-in file upload capabiliy:

    Jello form view with attachment

    Upon upload complete, the attachment is temporarily kept in the BlobStore and the response will contain the following details:

    d {
    	fileName: "Angelina Jolie.jpg"
    	fileType: "image/jpeg"
    	key: "ICpxhCE2TJnSnATv_Q4P6Q"
    	size: 14426
    }
    

    The actual value that need to be saved in the attachment field is the key. The attachment will be deleted if you will not save the associated instance in a timely manner (typically within 10 minutes).


    - Download / Display
    To get the actual value of the attachent, use the folloing REST call:
    /jello/data/NS/Entity(id)/element$value
    If the attchment is an image, this call will return the actual image binary content (much like refering to any image URL). For any other file types, this call will download the file. To download an image attachment, add the following to the request:
    /jello/data/NS/Entity(id)/element$value?$download=true

    Sometime it can be useful to display the uploaded image even if it was not yet been saved. It typicaly done in order to give the user feedbake before saving. To get the uploaded image use the following special request:
    /jello/data/NS/Entity(id)/element<attachment-key>$value


    - Get the attachment Info
    /jello/data/NS/Entity(id)/element$info
    Jello Attachment info REST call
    You can also get the attachment info by using $expand: Jello Attachment info REST call

    tableView special attachment info parameter:
    $attachmentPreview=fileName|fileType|fileSize|image|key  (default=image)

    attachment info parameter

    Last updated December 30, 2015.