cancel
Showing results for 
Search instead for 
Did you mean: 

Subir archivos desde flex

eduandres01_994
Champ in-the-making
Champ in-the-making
Hola a todos!!
Estoy intentando subir archivos a Alfresco desde Flex con el siguiente web script:

<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>

El problema es que al tratar de ejecutar el web script desde flex para subir el archivo obtengo el siguiente error:

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()

Dice que formdata no esta definido, no se que mas tengo que hacer para que el web script se ejecute bien.
Agradesco sus colaboraciones.
Gracias!! Smiley Very Happy
10 REPLIES 10

lexcorp
Champ in-the-making
Champ in-the-making
Que tal…

He estado leyendo tu post acerca de la integracion de flex con alfresco para subir un archivo, seria posible que me facilitaras o postearas un ejemplo de como subir los archivos ya que por lo que leo en tu post haz logrado resolver un problema que tenias, pretendo realizar lo mismo un upload de archivos desde flex pero no tengo ni idea de como iniciar, solo he leido algo  de webscripts y he seguido unos ejemplos, pero por la parte de flex no tengo idea…


Podrias postear el codigo que usaste en flex…
Getting started

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.