cancel
Showing results for 
Search instead for 
Did you mean: 

Importing files to upload

z3r0
Champ in-the-making
Champ in-the-making
Hi,
can someone give me alternatives to upload files. I use just the following piece of code:

// Open the file and convert to byte array
            InputStream viewStream = newContentNode.getClass().getClassLoader().getResourceAsStream("test.jpg");
            byte[] bytes = null;
         try
         {
            bytes = ContentUtils.convertToByteArray(viewStream);
         }
         catch (Exception e)
         {
            …
         }
           
            // Write the content
            ContentServiceSoapBindingStub contentService = WebServiceFactory.getContentService();
            Content contentRef = null;
         try
         {
            contentRef = contentService.write(newContentNode, Constants.PROP_CONTENT, bytes, format);
         }
         catch (ContentFault e)
         {
            …
         }
         catch (RemoteException e)
         {
            …
         }
My problem is that the file test.jpg is in the same folder as the class. But I want to upload files from another folder.
Here is test.jpg : ProjectFolder/WEB-INF/classes/package1/package2/
But I want from that folder. : ProjectFolder/TempFolder/

This code does not work.

InputStream viewStream = newContentNode.getClass().getClassLoader().getResourceAsStream("../../../../../TempFolder/test.jpg");

Has anyone a solution for this problem or an idea?
1 REPLY 1

steffen
Champ in-the-making
Champ in-the-making
the only way i konw how to do this, is to use the servlet conext to get the real (filesystem) path of the file:

void myFunc(ServletContext context) {

   //returns full path. Ex: C:\tomcat\5.5\webapps\myapp\ProjectFolder\TempFolde\test.jpg
    String fullCanonicalPath = context.getRealPath("/ProjectFolder/TempFolder/test.jpg");
    FileInputStream fis = new FileInputStream(fullCanonicalPath);

}

with getClassLoader().getResourceAsStream() you can only access files in the classpath.

steffen
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.