Streaming upload with Alfresco API

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2014 10:56 AM
Hi,
I'm implementing a Java BackedWebscript. I need to upload a large file to an Alfresco node. I see this class: UploadContentServlet, but I don't know if work fine for large files or better do it with another class.
I see also the code of this class, but I don't find examples using it. Only REST calls like /alfresco/upload/workspace/SpacesStore/0000-0000-0000-0000/myfile.pdf. But because I'm doing a Java Backed, I can't do REST calls inside my Java Backed. I suppose that only can use the Alfresco API.
Can you give me an example, please? To see how can I do this streaming uploads?
Thanks!
I'm implementing a Java BackedWebscript. I need to upload a large file to an Alfresco node. I see this class: UploadContentServlet, but I don't know if work fine for large files or better do it with another class.
I see also the code of this class, but I don't find examples using it. Only REST calls like /alfresco/upload/workspace/SpacesStore/0000-0000-0000-0000/myfile.pdf. But because I'm doing a Java Backed, I can't do REST calls inside my Java Backed. I suppose that only can use the Alfresco API.
Can you give me an example, please? To see how can I do this streaming uploads?
Thanks!
Labels:
- Labels:
-
Archive
5 REPLIES 5
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2014 11:40 AM
The trick with writing Java web script controllers for streaming is the following annotation which gives you control over the stream rather than the contents being buffered
by the framework. Look for scripts that define this. If you already have the content then just use the Java API.
by the framework. Look for scripts that define this. If you already have the content then just use the Java API.
<!– turn off the multipart formdata processing –> <formdata multipart-processing="false" />

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2014 01:27 PM
Sorry, I dont understand. Where I need to put this script? The formdata multipart procesing. I only have a java backed webscript, the document to upload is in a directory and I know the path. I dont have forms in html or javascript. Only my java webscript class.
I copy this code from the uploadservlet. Is all that I need to do to put the content with streaming to a noderef? Or Im wrong?
ServiceRegistry serviceRegistry = getServiceRegistry(getServletContext());
ContentService contentService = serviceRegistry.getContentService();
MimetypeService mimetypeService = serviceRegistry.getMimetypeService();
InputStream is = req.getInputStream();
BufferedInputStream inputStream = new BufferedInputStream(is);
// Try and get the content writer ContentWriter writer = contentService.getWriter(nodeRef, propertyQName, true);
// Set the mimetype and encoding writer.setMimetype(mimetype); writer.setEncoding(encoding);
// Stream the content into the repository writer.putContent(inputStream);
A lot of users may use this webscript at the same time.
putContent put the content with streaming? No problems if the content is very big?
Thanks again!
I copy this code from the uploadservlet. Is all that I need to do to put the content with streaming to a noderef? Or Im wrong?
ServiceRegistry serviceRegistry = getServiceRegistry(getServletContext());
ContentService contentService = serviceRegistry.getContentService();
MimetypeService mimetypeService = serviceRegistry.getMimetypeService();
InputStream is = req.getInputStream();
BufferedInputStream inputStream = new BufferedInputStream(is);
// Try and get the content writer ContentWriter writer = contentService.getWriter(nodeRef, propertyQName, true);
// Set the mimetype and encoding writer.setMimetype(mimetype); writer.setEncoding(encoding);
// Stream the content into the repository writer.putContent(inputStream);
A lot of users may use this webscript at the same time.
putContent put the content with streaming? No problems if the content is very big?
Thanks again!
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2014 03:15 AM
You need to put the script into the description xml file of the webscript you want to implemente
<code>
<webscript>
<shortname>your webscript name</shortname>
<description>…..</description>
….
<!– turn off the multipart formdata processing –>
<formdata multipart-processing="false" />
</webscript>
In your java backed webscript,you should do following steps:
1.parse the mutipart form
2.get the input stream from mutipart form
3.get the content writer for a node
4.put content stream into it.

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2014 04:00 AM
The problem is: I have the document to upload in a path that an applications puts in before. I don't have form. I just read the path in my java backed webscript and read the archive. In this case, I suppose that the formdata multipart-profesing has no effect. It's ok? How can I upload with streaming in this case?
Example:
FileInputStream fis = new FileInputStream( path );
BufferedInputStream inputStream= new BufferedInputStream(fis);
ContentWriter writer = getContentService().getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
writer.putContent(inputStream);
Thanks!
Example:
FileInputStream fis = new FileInputStream( path );
BufferedInputStream inputStream= new BufferedInputStream(fis);
ContentWriter writer = getContentService().getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
writer.putContent(inputStream);
Thanks!
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2014 08:52 AM
I'am sorry I 'am very clear about what you are up to.
If you want to implement a Java BackedWebscript for alfresco and you file is already uploaded to your alfresco server.
Then the code you paste will just work
Or you can just use
If you want to implement a Java BackedWebscript for share ,you file is already uploaded to your share server,and you want to upload it to alfresco server.
Then you can call the inbed /alfresco/service/api/upload api.
If you want to implement a Java BackedWebscript for alfresco and you file is already uploaded to your alfresco server.
Then the code you paste will just work
Or you can just use
ContentWriter.putContent(File file)
methodIf you want to implement a Java BackedWebscript for share ,you file is already uploaded to your share server,and you want to upload it to alfresco server.
Then you can call the inbed /alfresco/service/api/upload api.
