This custom object uploads a file through the API.
Note: The platform applies a restriction on the total number of bytes posted to ScriptoService. By default this limit is 16MB. If your script surpasses that limit, the Platform will return an error. See your Platform administrator for complete details.
Name: UploadFile
Type: Action
Description: (type your own)
Source Code:
package ScriptoEnhancement
import groovy.xml.MarkupBuilder
import static com.axeda.drm.sdk.scripto.Request.*;
// initialize the XML response
def writer = new StringWriter()
def xml = new MarkupBuilder(writer)
def numAttachments = attachments.size()
def description = attachments.description
// file content is available as an input stream
InputStream xmlFile = attachments.xmlFile;
InputStream zipFile = attachments.zipFile;
try {
// just get the string body content
xml.Attachments(count:numAttachments) {
xml.Description(description)
xml.xmlFile("File found: ${xmlFile.class.name}") {
xml.Contents(xmlFile.getText())
}
xml.zipFile("File Found: ${zipFile.class.name}")
}
} catch (Exception e) {
StringWriter logStringWriter = new StringWriter();
PrintWriter logPrintWriter = new PrintWriter(logStringWriter)
e.printStackTrace(logPrintWriter)
logger.error("Exception occurred in ScriptoUndeclaredParamsTest.groovy: ${logStringWriter.toString()}")
xml.error() {
faultcode ("Groovy Exception")
faultstring(e.getMessage())
}
}
return ["Content-Type": "application/xml","Content":writer.toString()]
Parameters:
Variable name |
Display name |
Username |
(REQUIRED) The name of the calling user |