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.

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.
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.
pagName  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 
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 Java Script API