AnsweredAssumed Answered

PDF file upload to repo not working

Question asked by sridharvedhana on May 26, 2009

I am trying to upload pdf file to repo server. The file is getting uploaded, but the issues is that when I login to Alfresco and click on that pdf link, it is showing me full-white blank pdf doc.

my code is :-

                        Reference baseFolderRef = null;
             baseFolderRef = n[0].getReference();
             System.out.println("baseFolderRef UUID is "+baseFolderRef.getUuid());
             System.out.println("baseFolderRef Path is "+baseFolderRef.getPath());
             ParentReference parentReference2 = new ParentReference(
                                   Constants.createQNameString(Constants.NAMESPACE_CONTENT_MODEL, "sample_content"));
             NamedValue[] properties2 = new NamedValue[]{Utils.createNamedValue(Constants.PROP_NAME, fullyQualifiedPhysicalPath.substring(fullyQualifiedPhysicalPath.lastIndexOf("/")+1))};
             CMLCreate create2 = new CMLCreate("1", parentReference2, null, null, null, Constants.TYPE_CONTENT, properties2);
             CML cml2 = new CML();
             cml2.setCreate(new CMLCreate[]{create2});
             UpdateResult[] results2 = WebServiceFactory.getRepositoryService().update(cml2); 
             // Set content
             ContentFormat format = new ContentFormat(MimetypeMap.MIMETYPE_PDF, "UTF-8");
             Content contentFile =  WebServiceFactory.getContentService().write(results2[0].getDestination(), Constants.PROP_CONTENT, content, format);
             System.out.println("Sucessfully dumped file to Alfresco, File url is "+contentFile.getUrl());

fullyQualifiedPhysicalPath is the input filepath ie C:/temp/store/A.pdf

Let me know if there is anything wrong in above code.