cancel
Showing results for 
Search instead for 
Did you mean: 

Creating file in the repository

oluwasegzy
Champ in-the-making
Champ in-the-making
I am writing a java backed webscript to upload a file into the Alfresco repository,

My challenge is that the i dont understand how to create a directory in the repository for the file

this is my code

String  nodePath = "" + repository.getCompanyHome();
      
      System.out.println("File name is " + filefield.getFilename());
      InputStream fileContent=filefield.getContent().getInputStream();
      
      File uploadedFile=new File(nodePath + "/" + filefield.getFilename());
      FileWriter writer = new FileWriter(uploadedFile);

i keep getting an exception that the file i created is does not exist when i want to use it in the line

FileWriter writer = new FileWriter(uploadedFile);

which implies that the directory i specify for the file is invalid


Please i need help on this
2 REPLIES 2

mrogers
Star Contributor
Star Contributor
You shouldn't be attempting to create files directly in the content store.    Instead you should be using a contentWriter.

So you create a node with nodeService or fileFolderService,  get a content writer and then write the cm:content property.

// Something like this.

      ChildAssociationRef childRef = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CONTAINS, localQName, ContentModel.CONTENT, contentProps);
             
        ContentWriter writer = fileFolderService.getWriter(childRef.yyyy);
         writer.setMimetype(file.getMimeType());
         writer.setEncoding(file.getEncoding());
         writer.putContent(xxx);


Actua

oluwasegzy
Champ in-the-making
Champ in-the-making
Pls I dont understand the scriptlet you have explain. Can you please send me a full sample code?
Thanks for your support