cancel
Showing results for 
Search instead for 
Did you mean: 

companyname not defined when attempting to implemment Upload Dashlet example

djsumdog
Champ in-the-making
Champ in-the-making
So I was attempting to implement the following File Upload tutorial:

http://wiki.alfresco.com/wiki/Web_Scripts_Examples#File_Upload

and my Dashlet is just named sumit and my sumit.post.js file looks like the following:


var filename = null;
var content = null;
var title = "";
var description = "";

// locate file attributes
for each (field in formdata.fields)
{
  if (field.name == "title")
  {
    title = field.value;
  }
  else if (field.name == "desc")
  {
    description = field.value;
  }
  else if (field.name == "file" && field.isFile)
  {
    filename = field.filename;
    content = field.content;
  }
}

// ensure mandatory file attributes have been located
if (filename == undefined || content == undefined)
{
  status.code = 400;
  status.message = "Uploaded file cannot be located in request";
  status.redirect = true;
}
else
{
  // create document in company home for uploaded file
  upload = companyhome.createFile("upload" + companyhome.children.length + "_" + filename) ;

  upload.properties.content.write(content);
  upload.properties.content.setEncoding("UTF-8");
  upload.properties.content.guessMimetype(filename);

  upload.properties.title = title;
  upload.properties.description = description;
  upload.save();

  // setup model for response template
  model.upload = upload;
}


and I get the following error after I attempt a file upload:


Error Message: 06100003 Failed to execute script 'classpath*:alfresco/site-webscripts/org/alfresco/components/dashlets/sumit.post.js': 06100002 ReferenceError: "companyhome" is not defined. (file:/var/lib/tomcat-7-share/webapps/share/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/components/dashlets/sumit.post.js#34)
Server: Alfresco Spring WebScripts - v1.2.0 (Release 1207) schema 1,000


I was looking through trying to figure out where companyname was defined in the example, when I discovered it was in the global API:

http://wiki.alfresco.com/wiki/4.0_JavaScript_API

Is there something I have to do to the sumit.post.desc.xml or sumit.post.properties file I need to include in order to get access to that variable?
2 REPLIES 2

zladuric
Champ on-the-rise
Champ on-the-rise
There are two obvious things to ask first:
1. Did you deploy this webscript to Share or Alfresco? Companyhome is only available in Alfresco.
2. Are you authenticated? I'm not 100% sure, but I think nonauthenticated (not guest) users can't have companyhome object. (I'd need to check that, though).

djsumdog
Champ in-the-making
Champ in-the-making
Ah. Okay. I am authenticated, but I deployed this to Share, not Alfresco. Is there an example of uploading files in a share dashlet I could use?
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.