问题
I have a custom service /hayts the processes file uploads and metadata.
the same files work when following the MultiPart Forms Tutorial.
However, when I bundle the files into My Share application. I can load the form submit it to upload the file. But the POST processing JS fails.
The Web Script /share/page/hayts has responded with a status of 500 - Internal Error.
500 Description: An error inside the HTTP server which prevented it from fulfilling the request.
Message: 11120001 Failed to execute script 'classpath*:alfresco/web-extension/site-webscripts/com/github/raystorm/smalgyax/hayts/hayts.post.js': 11120000 ReferenceError: "companyhome" is not defined. (jar:file:/usr/local/tomcat/webapps/share/WEB-INF/lib/smalgyax-share-1.0.0-SNAPSHOT.jar!/alfresco/web-extension/site-webscripts/com/github/raystorm/smalgyax/hayts/hayts.post.js#35)
Server: Spring WebScripts - v7.10.0 schema 1,000
For the following line: upload = companyhome.createFile(file.filename, type);
Why does it work when ingested via the UI at /alfresco/service/multipart but not for my share service version /share/service/hayts?
回答1:
Alfresco and Share and not the same thing as you probably know, Alfresco being the platform and Share being the user interface.
So root object available to either are not the same.
https://docs.alfresco.com/6.1/references/APISurf-rootscoped.html
https://docs.alfresco.com/4.2/references/API-JS-rootscoped.html
回答2:
You can use the FileFolderService to create a folder and then a file in this new folder. We use the ServiceRegistry to get to the FileFolderService, The ServiceRegistry bean is injected into the Web Script controller bean.
/**
* Create a file under the passed in folder.
*
* @param folderInfo the folder that the file should be created in
* @param filename the name of the file
* @param fileTxt the content of the file
* @return a FileInfo object with data about the new file, such as NodeRef
*/
private FileInfo createFile(FileInfo folderInfo, String filename, String fileTxt) throws FileExistsException {
// Create the file under passed in folder, the file will be empty to start with
FileInfo fileInfo = serviceRegistry.getFileFolderService().create(
folderInfo.getNodeRef(), filename, ContentModel.TYPE_CONTENT);
// Get the NodeRef for the new file from the FileInfo object
NodeRef newFileNodeRef = fileInfo.getNodeRef();
// Add some content to the file
ContentWriter writer = serviceRegistry.getFileFolderService().getWriter(newFileNodeRef);
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
writer.setEncoding("UTF-8");
writer.putContent(fileTxt);
return fileInfo;
}
来源:https://stackoverflow.com/questions/65262074/companyhome-not-defined-error-in-bundle-service-post-js-file-in-alfresco-share