10-27-2008 11:17 AM
<webscript>
<shortname>upload</shortname>
<description>Uploads file </description>
<url>/esoft/upload</url>
<format default="xml">argument</format>
<authentication>user</authentication>
<transaction>required</transaction>
</webscript>
var filename = null;
var content = null;
var mimetype = null;
var name = null;
var title = null;
var description = null;
var author = null;
var nodeid = null;
var storeid = null;
var path = null;
var thumbnailNames = null;
// locate file attributes
for each (field in formdata.fields)
{
switch (String(field.name).toLowerCase())
{
case "title":
title = field.value;
break;
case "desc":
description = field.value;
break;
case "author":
author = field.value;
break;
case "name":
// for having name propertie different than original filename
name = field.value;
break;
case "file":
if (field.isFile)
{
filename = field.filename;
content = field.content;
}
break;
case "mimetype":
mimetype = field.value;
break;
case "nodeid":
nodeid = field.value;
break;
case "storeid":
storeid = field.value;
break;
case "path":
path = field.value;
break;
case "thumbnails":
thumbnailNames = field.value;
break;
}
}
var isAvmNode = false;
if ((nodeid != null) && (nodeid != ""))
{
// get folder to upload into using doc mgt nodeid
model.folder = search.findNode("workspace://SpacesStore/" + nodeid);
}
else if ( (storeid != null) && (storeid != "") && (path != null) && (path != "") )
{
// get folder to upload into with avm storeid and avm path
var store = avm.lookupStore(storeid);
if (store != null)
{
var pathWithStore = storeid + ":" + path;
model.folder = avm.lookupNode(pathWithStore);
isAvmNode = true;
}
}
else if ((path != null) && (path != ""))
{
// get folder to upload into with doc mgt path
model.folder = roothome.childByNamePath(path);
}
var version = server.version;
var versionNum = parseFloat(version);
// ensure folder and mandatory file attributes have been located
if (model.folder == null || filename == undefined || content == undefined)
{
status.code = 400;
status.message = "Uploaded file cannot be located in request";
status.redirect = true;
}
else
{
// create document in model.folder for uploaded file
upload = model.folder.createFile("upload" + model.folder.children.length + "_" + filename);
upload.properties.content.write(content);
upload.properties.content.mimetype = mimetype;
if (versionNum >= 2.9)
{
upload.properties.content.encoding = "UTF-8";
}
else
{
upload.properties.encoding = "UTF-8";
}
if (isAvmNode == false)
{
if (name != null)
{
upload.properties.name = name;
}
else
{
upload.properties.name = filename;
}
if (title != null)
{
upload.properties.title = title;
}
if (description != null)
{
upload.properties.description = description;
}
if (author != null)
{
upload.properties.author = author;
}
upload.save();
}
else
{
// need to use rename on avm nodes
if (name != null)
{
upload.rename(name);
}
else
{
upload.rename(filename);
}
// note setting other properties does not work currently
// with the javascript api on avm nodes
upload.save();
}
if (versionNum >= 3.0)
{
if (thumbnailNames != null)
{
var thumbnails = thumbnailNames.split(",");
for (var i = 0; i < thumbnails.length; i++)
{
var thumbnailName = thumbnails[i];
if(thumbnailName != "" && thumbnailService.isThumbnailNameRegistered(thumbnailName))
{
upload.createThumbnail(thumbnailName, true);
}
}
}
}
model.upload = upload;
}
<upload>
<server>Alfresco ${server.edition} v${server.version}</server>
<folder>
<name>${folder.name}</name>
<id>${folder.id}</id>
<path>${folder.displayPath}/${folder.name}</path>
</folder>
<node>
<name>${upload.properties.name}</name>
<id>${upload.id}</id>
<path>${upload.displayPath}/${upload.name}</path>
<title>${upload.properties.title!}</title>
<description>${upload.properties.description!}</description>
<#if upload.isDocument>
<author>${upload.properties.author!}</author>
<size>${upload.properties.content.size}</size>
</#if>
</node>
</upload>
Error: Execution of web script failed:Failed to execute script '/esoft/upload.post.js (in classpath store file:C:/Alfresco/tomcat/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts)': Failed to execute script '/esoft/upload.post.js (in classpath store file:C:/Alfresco/tomcat/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts)': ReferenceError: "formdata" is not defined. (AlfrescoScript#20) URL=http://localhost:8080/alfresco/service/flexspaces/uploadNew
at org.alfresco.framework.service.webscript::WebScriptService/raiseFailureEvent()[C:\dev\WorkSpace\AlfrescoConFlex\My\org\alfresco\framework\service\webscript\WebScriptService.as:284]
at org.alfresco.framework.service.webscript::WebScriptService/onResultEvent()[C:\dev\WorkSpace\AlfrescoConFlex\My\org\alfresco\framework\service\webscript\WebScriptService.as:251]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()[E:\dev\3.1.0\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:170]
at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler()[E:\dev\3.1.0\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:193]
at mx.rpc::Responder/result()[E:\dev\3.1.0\frameworks\projects\rpc\src\mx\rpc\Responder.as:43]
at mx.rpc::AsyncRequest/acknowledge()[E:\dev\3.1.0\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:74]
at DirectHTTPMessageResponder/completeHandler()[E:\dev\3.1.0\frameworks\projects\rpc\src\mx\messaging\channels\DirectHTTPChannel.as:381]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
10-27-2008 11:36 AM
<form action="${url.service}" method="post" enctype="multipart/form-data" accept-charset="utf-8">
<tr><td>Fichero:<td><input type="file" name="file">
<tr><td>Titulo:<td><input name="title">
…
Espero que esto resuelva tu problema. 10-27-2008 05:05 PM
10-27-2008 05:16 PM
<form action="${url.service}" method="post" enctype="multipart/form-data" accept-charset="utf-8">
El action si te fijas es la url del servicio actual, pues ambos webscripts comparten la url, lo único que los diferencia es el método (que el formulario indica que es post). Además, para que funcione debe tener el enctype="multipart/form-data", así el webscript POST podrá acceder a la información introducida en el formulario mediante el objeto formdata.10-27-2008 06:23 PM
10-28-2008 11:38 AM
10-28-2008 12:03 PM
<webscript>
<shortname>crop Content</shortname>
<description>gets cropped content as text</description>
<url format="xml" template="/esoft/preview.xml?node={node}"/>
<format default="xml">extension</format>
<authentication>user</authentication>
<transaction>required</transaction>
</webscript>
node = search.findNode(args['node']);
model.node = node;
<#setting locale="en_US">
<#assign c= "">
<#assign i= "#">
<#if node.isDocument>
<#assign isImage=node.isDocument && (node.mimetype = "image/gif" || node.mimetype = "image/jpeg" || node.mimetype = "image/png")>
<#if isImage>
<#assign i =url.context+ node.url+"?"+node.size>
<#assign i =url.serviceContext+"/api/node/content/"+node.nodeRef.storeRef.protocol+"/"+node.nodeRef.storeRef.identifier+"/"+node.nodeRef.id+"/"+node.name?url>
<#else>
<#if node.properties.content??>
<#assign c= crop(node.properties.content, 1000)>
</#if>
</#if>
</#if>
<dataset>
<row>
<content>${c?xml}</content>
<image>${i}</image>
</row>
</dataset>
try{
var urlRequest:URLRequest = new URLRequest("http://localhost:8080/alfresco/service/esoft/upload" + "?alf_ticket=" + ticket);
urlRequest.method = URLRequestMethod.POST;
var params:URLVariables = new URLVariables();
params.title = file.name;
params.desc = "Contenido de prueba desde flex";
urlRequest.data = params;
file.upload(urlRequest,"file");
}catch(err:Error){
trace("Error cargando archivo" + err.message);
}
10-28-2008 12:18 PM
10-28-2008 12:47 PM
preview.enabled = false;
var url:String = "http://localhost:8080/alfresco/service/my/cropContent1.xml?node=" + folders.selectedItem.noderef.toString();
var webScrip:WebScriptService = new WebScriptService(url,WebScriptService.GET,muestraPreview,null,true);
var params:Object = new Object();
params.ticket = ticket;
var token:AsyncToken = webScrip.execute(params);
10-28-2008 05:43 PM
upload.properties.content.mimetype = mimetype;
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.