05-13-2014 02:00 AM
var paramsArray = new String(url.extension).split("/")
var homeId = paramsArray[0];
var fileId = paramsArray[2];
var filename = null;
var content = null;
var tagsList;
var title;
var description;
for each (field in formdata.fields) {
if (field.name == "title") {
title = field.value;
}
else if (field.name == "description") {
description = field.value;
}
else if (field.name == "tagsList") {
tagsList = field.value;
}
if (field.name == "file" && field.isFile) {
filename = field.filename;
content = field.content;
}
}
if (homeId.length == 0 || fileId.length == 0) {
status.code = 400;
status.message = "A required parameter has not been provided.";
status.redirect = true;
} else if (filename == undefined || content == undefined) {
// ensure mandatory file attributes have been located
status.code = 400;
status.message = "Uploaded file cannot be located in request.";
status.redirect = true;
} else {
var fileExists = false;
var file;
var homesFolder = companyhome.childByNamePath("FOLDER");
var targetFolder = homesFolder.childByNamePath(homeId);
var duplicateFileName = false;
if (targetFolder != undefined) {
var children = targetFolder.getChildren();
for (var i = 0; i < children.length; i++) {
if (new String(children.getId()).valueOf() == new String(fileId).valueOf()) {
fileExists = true;
file = children;
} else if (new String(children.getName()).valueOf() == new String(filename).valueOf()) {
//File name already belongs to another file.
duplicateFileName = true;
}
}
}
if (fileExists && !duplicateFileName) {
if (title != undefined) {
file.properties.title = title;
}
if (description != undefined) {
file.properties.description = description;
}
var fileTags = file.getTags();
for (var i = 0; i < fileTags.length; i++) {
if (new String(fileTags).substring(0,4) != "api.") {
file.removeTag(fileTags);
}
}
file.addTag(tagsList);
if (filename != undefined && !new String(filename).valueOf() == "") {
file.properties.name = filename;
file.properties.content.write(content);
file.properties.content.setEncoding("UTF-8");
file.properties.content.guessMimetype(filename);
}
file.save();
model.upload = file;
model.homeid = homeId;
} else if (!fileExists) {
status.code = 400;
status.message = "File specified (" + fileId + ") does not exist for Id: " + homeId;
status.redirect = true;
} else {
status.code = 400;
status.message = "A file with this name already exists: " + filename;
status.redirect = true;
}
05-13-2014 11:13 PM
05-14-2014 10:17 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.