04-14-2010 12:07 PM
04-14-2010 01:37 PM
04-22-2010 01:11 PM
var filename = null;
var content = null;
var title = "";
var description = "";
var uploadDirectory = null;
for each (field in formdata.fields) {
if (field.name == "name") {
model.name = field.value;
}
if (field.name == "file" && field.isFile) {
content = field.content;
mimetype = field.mimetype;
}
if (field.name == "filename") {
filename = field.value;
}
if (field.name == "title")
{
title = field.value;
}
if (field.name == "desc")
{
description = field.value;
}
if (field.name == "uploadDirectory") {
uploadDirectory = field.value;
}
}
//Place the file in the appropriate folder.
//If not set it goes into 'company home'
if (uploadDirectory !== null) {
//now determine if this folder exists … create it if required.
myArray = uploadDirectory.split("/");
var BuildPath="";
var DoneFolder = null;
var testFolder = "";
var startFolder;
for (x in myArray)
{
//does this folder exist?
if (DoneFolder === null)
{
startFolder = companyhome;
}
else
{
startFolder = companyhome.childByNamePath(DoneFolder);
}
if(DoneFolder === null){
testFolder = myArray[x];
}
else
{
testFolder = DoneFolder + "/" + myArray[x];
}
testNode = companyhome.childByNamePath(testFolder);
if (testNode === null){
//this folder doesn't exist create it.
var myfolder = startFolder.createFolder(myArray[x]);
}
if (DoneFolder === null){
DoneFolder = myArray[x];
}
else
{
DoneFolder = DoneFolder + "/" + myArray[x];
}
}
var targetFolder = companyhome.childByNamePath(uploadDirectory);
}
else
{
var targetFolder = companyhome;
}
// handle overwriting file if required
// handle assigning aspects
// Does the file already exist?
var existingFile = companyhome.childByNamePath(uploadDirectory + "/" + filename);
if (existingFile === null){
//this is a new file.
var newDoc = targetFolder.createFile(filename);
newDoc.properties.content.write(content);
newDoc.properties.content.mimetype = mimetype;
newDoc.properties.content.encoding = "UTF-8";
newDoc.properties.title = title;
newDoc.properties.description = description;
// Make file versionable .. autoversion & create initial version
var props = new Array(2);
props["cm:autoVersion"] = true;
props["cm:initialVersion"] = true;
newDoc.addAspect("cm:versionable", props);
// now save it
newDoc.save();
}
else
{
//this is an existing file.
//overwrite it.
//but first make sure old version preserved.
if (!existingFile.hasAspect("cm:versionable")){
//Turn on versioning and save original
var props = new Array(2);
props["cm:autoVersion"] = true;
props["cm:initialVersion"] = true;
existingFile.addAspect("cm:versionable", props);
existingFile.save();
}
existingFile.properties.content.write(content);
model.document = existingFile;
existingFile.properties.content.guessMimetype(filename);
existingFile.properties.content.encoding = "UTF-8";
existingFile.save();
}
04-22-2010 01:29 PM
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.