cancel
Showing results for 
Search instead for 
Did you mean: 

How Can I get a Java.io.File from a Content file?

robertoroberto
Champ in-the-making
Champ in-the-making
How Can I get a Java.io.File from a Content file in Alfesco?
By Wes service?
Can you post an example code?
4 REPLIES 4

rivarola
Champ on-the-rise
Champ on-the-rise
Hello,

You can get a ContentReader from the ContentService. This ContentReader is often (but not always) a FileContentReader which has a getFile method.
But you should * not * access repository files this way. Why not simply using InputStream and OutputStream provided by the ContentReader and ContentWriter ?

jlabuelo
Champ on-the-rise
Champ on-the-rise
Hi Rivarola and Roberto

I am trying to do the same, get a content node from Alfresto and transform it in a java.io.file as then I will need to assign it to a java.awt.Image.

I am trying to access the content and assign it to the java.io.File vable, but I get error messages that means the way I do it is wrong. I am using the ContentReader as you suggest in the post, however I dont find the getFile() method you say:
Node Documento_Aux =  this.browseBean.getDocument();               File imagen_Original ;               ContentReader lectura = this.getFileFolderService().getReader(Documento_Aux.getNodeRef());               lectura.getContent(imagen_Original);  //Here it fails saying that the file is incorrect or null                                                                BufferedImage orignalBF  = ImageIO.read(imagen_Original);                            Image original_Img = toImage(orignalBF);                           ‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Any ideas of what I am duing wrong to use ContentReader to get the file from Alfresco?

Thanks a lot in advance guys

rogier_oudshoor
Champ in-the-making
Champ in-the-making
I think this should workd:

BufferedImage image = ImageIO.read(reader.getContentInputStream());‍

Ask your reader for the stream, and have the image read that.

jlabuelo
Champ on-the-rise
Champ on-the-rise
Thanks a lot worked fine now!!
Welcome to the new Hyland Connect. Get started or submit feedback.