As we transition to the new Hyland Community, some post links may be temporarily disrupted as we finalize redirects. We apologize for the inconvenience and are working to resolve this as quickly as possible. Details.
public class FileUploadWebScript extends DeclarativeWebScript { private ContentService contentService; private Repository repository; private FileFolderService fileFolderService; public void setContentService(ContentService contentService) { this.contentService = contentService; } public void setRepository(Repository repository) { this.repository = repository; } public void setFileFolderService(FileFolderService fileFolderService) { this.fileFolderService = fileFolderService; } @Override protected Map<String, Object> executeImpl(WebScriptRequest req, Status status) { NodeRef companyHome = repository.getCompanyHome(); String filename = req.getParameter("filename"); NodeRef writeTo = fileFolderService.searchSimple(companyHome, filename); FormData formData = (FormData) req.parseContent(); FormData.FormField[] fields = formData.getFields(); for (FormData.FormField field : fields) { if (field.getName().equals("file") && field.getIsFile()) { Content content = field.getContent(); ContentWriter writer = contentService.getWriter(toWrite, ContentModel.PROP_CONTENT, true); writer.setMimetype(content.getMimetype()); writer.putContent(content.getInputStream()); } } Map<String, Object> model = new HashMap<String, Object>(); model.put("output", "Success."); return model; } }