cancel
Showing results for 
Search instead for 
Did you mean: 

Stream file into alfresco

tim-erwin
Champ in-the-making
Champ in-the-making
Hello!

Uploading files - especially huge ones - seems to be quite a common topic here. I few questions arised to me:

  1. Is there a way to stream a file into alfresco? I have two servers: a web server and the alfresco dms server. When somebody uploads content to the web server I immediately want to stream that into alfresco without first having the whole file stored on the web server.

  2. As huge file seem to be a problem for web services, is it clean/appropriate/… to use the contentUploadServlet instead - just for the upload? (btw: I hate mixing different techniques…)

  3. if (questions[2].getAnswer() == "yes") {How do I do that?}
Thank you,
Tim-Erwin
4 REPLIES 4

rwetherall
Confirmed Champ
Confirmed Champ
Hi,

Yes, web services, and in particular Axis, have issues with large files and the current solution is to use the UploadContentServlet.  This means the content can be streamed to the server and file size is not a limiting factor.

I appreciate your comment about mixing these methods, however going forward you will see us consolidating these various remote access techniques into one, coherent REST API.

Here a snip of code cut from a unit test that uploads some content from a file (using the upload servlet) and then creates a new node with that content.



      File testFile = somefile;

       // Put the content onto the server
       String contentData = ContentUtils.putContent(testFile);
      
       // Create the parent reference
       ParentReference parentRef = new ParentReference();
       parentRef.setStore(BaseWebServiceSystemTest.store);      parentRef.setUuid(BaseWebServiceSystemTest.rootReference.getUuid());
       parentRef.setAssociationType(Constants.ASSOC_CHILDREN);
       parentRef.setChildName(Constants.ASSOC_CHILDREN);
      
       String myFile = "test.jpg";
      
       // Create the content
       NamedValue[] properties = new NamedValue[]
       {
           Utils.createNamedValue(Constants.PROP_NAME, myFile),
           Utils.createNamedValue(Constants.PROP_CONTENT, contentData)
       };
       CMLCreate create = new CMLCreate("1", parentRef, null, null, null, Constants.TYPE_CONTENT, properties);
       CML cml = new CML();
       cml.setCreate(new CMLCreate[]{create});
       UpdateResult[] result = this.repositoryService.update(cml);


Cheers,
Roy

tim-erwin
Champ in-the-making
Champ in-the-making
Hey Roy,

thank you very much for your answer and the code snippet. Right now I can't see where in these lines the servlet is used, but I guess I will find out somehow… I suppose putContent() uses the servlet. Right?

Regards, Tim-Erwin

rwetherall
Confirmed Champ
Confirmed Champ
Hi,

Yes your assumption is correct, putContent() is just a helper method that does the work of calling the servlet for you.  If you have a look at its implementation it should make more sense.

Cheers,
Roy

diego_gonzalez
Champ in-the-making
Champ in-the-making
Hi, i'm trying to upload a file using UploadContentServlet.

My code:


….
// Put the content onto the server
            String contentData = ContentUtils.putContent(testFile);

            // Create the parent reference
            ParentReference parentRef = new ParentReference();
            parentRef.setStore(STORE);
            parentRef.setUuid(id);
            parentRef.setAssociationType(Constants.ASSOC_CHILDREN);
            parentRef.setChildName(Constants.ASSOC_CHILDREN);

            String myFile = fichero.getName();

            // Create the content
            NamedValue[] properties = new NamedValue[]
                    {
                            Utils.createNamedValue(Constants.PROP_NAME, myFile),
                            Utils.createNamedValue(Constants.PROP_CONTENT, contentData)
                    };
            CMLCreate create = new CMLCreate("1", parentRef, null, null, null, Constants.TYPE_CONTENT, properties);
            CML cml = new CML();
            cml.setCreate(new CMLCreate[]{create});
            UpdateResult[] result = this.repositoryService.update(cml);
….

When last line is executed
UpdateResult[] result = this.repositoryService.update(cml);
it's throws a exception:
transaction didn't commit: integrity failure

Can anybody help me?