GetAttachment function
Syntax
GetAttachment(URLSource, DirAndSysFileName, DirAndLocalFileName[, LocalDirEnvVar[, PreserveCase]])
Description
Use the GetAttachment function to download a file from its source storage location to the file system of the application server. The file system of the application server includes any directories accessible from the application server including those on local disks as well as on network shares.
Note:
All directories that are part of the destination full path name must exist before GetAttachment is called. The GetAttachment function will not create any directories on the application server's file system.
Additional information that is important to the use of GetAttachment can be found in the PeopleTools: PeopleCode Developer's Guide:
-
PeopleTools supports multiple types of storage locations.
See PeopleCode Developer’s Guide: Understanding File Attachment Storage Locations.
-
Certain characters are illegal in file names; other characters in file names are converted during file transfer.
-
Non-ASCII file names are supported by the PeopleCode file attachment functions.
See PeopleCode Developer’s Guide: Attachments with non-ASCII File Names.
-
The PeopleCode file attachment functions do not provide text file conversions when files are attached or viewed.
See PeopleCode Developer’s Guide: Considerations When Attaching Text Files.
Parameters
| Parameter | Description |
|---|---|
|
URLSource |
A reference to a URL. This can be either a URL identifier the form URL.URL_ID, or a string. This (along with the DirAndSysFileName parameter) indicates the file's source location. Note: When the URLSource parameter is specified as a string value, forward slashes (/) are required. Backward slashes (\) are not supported for a string value. See PeopleCode Developer’s Guide: Understanding URL Strings Versus URL Objects. |
|
DirAndSysFileName |
The relative path and file name of the file at the storage location. This is appended to URLSource to form the full URL where the file will be transferred from. This parameter takes a string value. Note: Because the DirAndSysFileName parameter is appended to the URL, it also requires forward slashes (“/”). Backward slashes (“\”) are not supported for this parameter. |
|
DirAndLocalFileName |
The name, relative path name, or full path name of the destination file on the application server. This parameter takes a string value. If you specify only a name or a relative path name for the destination file, the file will be placed in or relative to:
If you do not want to use the LocalDirEnvVar parameter or the value of the TMP environment variable in this way, you must specify a full path name as appropriate to the application server’s operating system. |
|
LocalDirEnvVar |
This optional parameter takes a string value. If LocalDirEnvVar is specified, then its value will be prefixed to the value of the DirAndLocalFileName parameter to form the full path name of the destination file on the application server’s file system. With this parameter, you can avoid the need to hard-code the full path name. If LocalDirEnvVar is not specified and the value of the DirAndLocalFileName parameter is already a full path file name, then that value will itself be used as the full path name that the downloaded file will have at its destination on the application server machine. If LocalDirEnvVar is not specified and the value of the DirAndLocalFileName parameter is not a full path file name, then the value of the TMP environment variable will be prefixed to the value of the DirAndLocalFileName parameter to form the full path name that the downloaded file will have at its destination on the application server machine. Note: In order to use the optional parameter PreserveCase, you must pass some value for LocalDirEnvVar. If you want to use the default behavior of LocalDirEnvVar and also use PreserveCase, you can specify "" (the empty string) for LocalDirEnvVar. Then the function behaves as if no value is specified. In this situation, if you wish to use the TMP environment variable, it must be explicitly specified. Note: Do not specify LocalDirEnvVar if you use an absolute path for the DirAndLocalFileName parameter. |
|
PreserveCase |
When searching for the file specified by the DirAndSysFileName parameter, PreserveCase specifies a Boolean value to indicate whether the case of its file name extension is preserved: True, preserve the case, False, convert the file name extension in DirAndSysFileName to all lowercase letters. The default value is False. For a particular file, use the same value for this parameter that was used when the file was originally uploaded. Warning! If you use the PreserveCase parameter, it is important that you use it in a consistent manner with all the relevant file-processing functions or you may encounter unexpected file-not-found errors. This is an optional parameter. |
Returns
You can check for either an integer or a constant value:
| Numeric Value | Constant Value | Description |
|---|---|---|
|
0 |
%Attachment_Success |
File was transferred successfully. |
|
1 |
%Attachment_Failed |
File transfer failed due to unspecified error. The following are some possible situations where %Attachment_Failed could be returned:
|
|
3 |
%Attachment_FileTransferFailed |
File transfer failed due to unspecified error during FTP attempt. The following are some possible situations where %Attachment_FileTransferFailed could be returned:
|
|
4 |
%Attachment_NoDiskSpaceAppServ |
No disk space on the application server. |
|
7 |
%Attachment_DestSystNotFound |
Cannot locate destination system for FTP.
|
|
8 |
%Attachment_DestSysFailedLogin |
Unable to login to destination system for FTP. The following are some possible situations where %Attachment_DestSysFailedLogin could be returned:
|
|
9 |
%Attachment_FileNotFound |
Cannot locate file. The following are some possible situations where %Attachment_FileNotFound could be returned:
|
Example
The following downloads
the file, HRarchive/NewHire/11042000resume.txt, from the FTP server to c:\NewHires\resume.txt on the application server machine.
&retcode = GetAttachment("ftp://anonymous:hobbit1@ftp.ps.com/HRarchive/", ⇒
"NewHire/11042000resume.txt", "c:\NewHires\resume.txt");
File System Considerations
If you are uncertain which type of file system the file is going to be transferred to, either a UNIX or Windows system, you should simply specify a file name for the DirAndLocalFileName parameter and either explicitly set the LocalDirEnvVar parameter or accept its default value, which is “TMP” (indicating that the value of the TMP environment variable will be used).
The following code example works for Windows systems, but not UNIX systems:
&retcode = GetAttachment(&FTPINFO, &SOURCEFILENAME, "c:\temp\resume.doc");
The following code example works for Unix systems, but not Windows systems:
&retcode = GetAttachment(&FTPINFO, &SOURCEFILENAME, "/tmp/resume.doc");
The following two examples work for both Windows and Unix systems:
&retcode = GetAttachment(&FTPINFO, &SOURCEFILENAME, "resume.doc");
&retcode = GetAttachment(&FTPINFO, &SOURCEFILENAME, "resume.doc", "PS_CFG_HOME");
WARNING:
If the effectively specified target directory that is to ultimately contain the downloaded file on the application server is a UNC (Universal Naming Convention) share, an error will occur and GetAttachment will fail to download the file.
You cannot use a share as the target directory—that is, as the ultimate destination—to download a file onto an application server using GetAttachment. However, you can use a subdirectory of a UNC share as the target directory.
For example, if a directory similar to the following were the target directory, GetAttachment would fail:
\\server_name\share_name
However, the following subdirectory of the same UNC share could be used with GetAttachment:
\\server_name\share_name\temp
Related Topics
- PeopleCode Developer’s Guide: Enabling Tracing on the Web Server or Application Server
- CleanAttachments function
- CopyAttachments function
- DeleteAttachment function
- DetachAttachment function
- MAddAttachment function
- PutAttachment function
- ViewAttachment function
- PeopleCode Developer’s Guide: Debugging File Attachment Problems