JavaScript API

Search:

Welcome

Login to contribute. Register if you haven't yet.

Need Support?

Search this site to find an answer. If you still need help, post a Question. Private or account-related support inquiries can be made at the Private Support forum.

Stay Informed

Are you receiving EditMe's monthly newsletter? Keep informed of product changes, tutorials and tips. Sign up here.

JavaScript API Class: Attachment

An instance of the Attachment class represents one version of an uploaded file. Attachments can be accessed using the "attachments" implicit object, which contains the attachments for the current page in alphabetic order by name, or by using the attachments property of a Page object.

Properties

Name  Type  Access
Description 
bytes Number
read
The size of the attached file in bytes.
className String read Returns "Attachment" to help identify that this object is an instance of the Attachment class.
date
Date
read
The date the attachment was uploaded. Current user's time zone is applied.
deleted
Boolean
read/write
True if the attachment is marked deleted.
description
String
read/write
The description of the attachment.
hidden
Boolean
read/write
True if the attachment is marked hidden.
name
String
read
The name of the attached file.
pageName  String
read
The name of the page this attachment is attached to.
size String
read
The size of the file in text format (e.g. 2MB).
user
String
read
The name of the user that uploaded the attachment.
version
Number
read

The version number of this attachment.

versionedName String
read
The version-specific file name for this attachment. For example, a file named image.jpg might have two different versions: image.1.jpg and image.2.jpg. The generic image.jpg name returned by the "name" property always returns the most recent version.
versions
Array of Attachments
read
Returns an array of all the versions of this attachment.

Functions

Name  Return Type
Description 
resize(String, Number1, Number2) Attachment

Assuming this attachment object represents an image, resizes the image file and retuns a new Attachment object representing the resized image. Most common web image formats are supported. Aspect ratio is always maintained when resizing. If called on a non-image or unsupported image format, returns null. Arguments are used as follows:

  1. String - prefix for the resized file. If called on an attachment named myfile.jpg and 'smaller-' is passed for this argument, the new attachment will be named 'smaller-myfile.jpg'.
  2. Number1 - the maximum height for the resized image. If 0, no limit will be set and the height will be defined in proportion to the width.
  3. Number2 - the maximum width for the resized image. If 0, no limit will be set and the width will be define in proportion to the height.
The returned Attachment object will have already been saved - no need to call save().
save()
none
Saves changes to an existing attachment. New attachments cannot be created via JavaScript.
toString()
String
Returns the equivalent of attachment.name.

Example

// get the attachments for the menu page
var atts = site.page("Menu").attachments;
// iterate through the array of attachments returned
for (i in atts) {
    // get an attachment from the array
    var att = attachments[i];
    // use various properties to create a descriptive string
    var s = "The file " + att.name + " was uploaded on " +
        att.date + " by " + att.user + ".";
    // ... do something with s

 

Return to JavaScript API


EditMe News & Blog