Tribune

Home » Liferay Portal » English » 3. Development

Vista Combinata Vista Piatta Vista ad Albero
Discussioni [ Precedente | Successivo ]
toggle
Yegor Bondar
Get File object from DocumentLibrary.
29 agosto 2011 23.56
Risposta

Yegor Bondar

Punteggio: New Member

Messaggi: 21

Data di Iscrizione: 23 agosto 2011

Messaggi recenti

Good day!
I have one more question.
I store my documents in Documents Library and want send some documents by email.
My portlet has form where user choses files and then this files must attach to email.

I work with DLFileEntryLocalServiceUtil and DLFileEntry. In this classes i didn`t find methods which gave me ability get object File or (Input/Output)Stream of my stored files.

How can I get object of stored file?

Tnx.
Victor Zorin
RE: Get File object from DocumentLibrary.
30 agosto 2011 0.11
Risposta

Victor Zorin

Punteggio: Liferay Legend

Messaggi: 1183

Data di Iscrizione: 14 aprile 2008

Messaggi recenti

A couple of code cuts:

(6.0)

java.io.InputStream istream =
DLFileEntryLocalServiceUtil.
getFileAsStream(PortalUtil.getCompanyId(req),
PortalUtil.getUserId(req),
PortalUtil.getScopeGroupId(req), summary.getFolderId(), summary.getName());

or (6.1)

java.io.InputStream istream = DLRepositoryLocalServiceUtil
.getFileAsStream(summary.getCreatedByUserId(),
fileId, summary.getVersion());
Jitendra Rajput
RE: Get File object from DocumentLibrary.
22 febbraio 2012 3.31
Risposta

Jitendra Rajput

Punteggio: Liferay Master

Messaggi: 875

Data di Iscrizione: 7 gennaio 2011

Messaggi recenti

how to achieve same thing in Liferay 5.2 ?
Alfonso Dou Oblanca
RE: Get File object from DocumentLibrary.
18 aprile 2012 0.03
Risposta

Alfonso Dou Oblanca

Punteggio: New Member

Messaggi: 3

Data di Iscrizione: 26 novembre 2008

Messaggi recenti

and for application in Java ?
I read this blog http://www.liferay.com/about-us/news/-/blogs/9308485/maximized, but it's not working for me.

This is my code:

 1    import org.apache.http.HttpHost;
 2    import org.apache.http.HttpResponse;
 3    import org.apache.http.NameValuePair;
 4    import org.apache.http.auth.AuthScope;
 5    import org.apache.http.auth.UsernamePasswordCredentials;
 6    import org.apache.http.client.AuthCache;
 7    import org.apache.http.client.entity.UrlEncodedFormEntity;
 8    import org.apache.http.client.methods.HttpPost;
 9    import org.apache.http.client.protocol.ClientContext;
10    import org.apache.http.impl.auth.BasicScheme;
11    import org.apache.http.impl.client.BasicAuthCache;
12    import org.apache.http.impl.client.DefaultHttpClient;
13    import org.apache.http.message.BasicNameValuePair;
14    import org.apache.http.protocol.BasicHttpContext;
15   
16    import java.io.File;
17    import java.io.FileOutputStream;
18    import java.io.IOException;
19    import java.io.OutputStream;
20    import java.util.ArrayList;
21    import java.util.List;
22   
23    public class Example {
24   
25        public static void main(String[] args) throws Exception {
26   
27            HttpHost targetHost = new HttpHost("localhost", 8080, "http");
28            DefaultHttpClient httpclient = new DefaultHttpClient();
29            httpclient.getCredentialsProvider().setCredentials(
30                    new AuthScope(targetHost.getHostName(), targetHost.getPort()),
31                    new UsernamePasswordCredentials("test", "test"));
32   
33            // Create AuthCache instance
34            AuthCache authCache = new BasicAuthCache();
35            // Generate BASIC scheme object and add it to the local
36            // auth cache
37            BasicScheme basicAuth = new BasicScheme();
38            authCache.put(targetHost, basicAuth);
39   
40            // Add AuthCache to the execution context
41            BasicHttpContext ctx = new BasicHttpContext();
42            ctx.setAttribute(ClientContext.AUTH_CACHE, authCache);
43   
44            HttpPost post = new HttpPost("/api/secure/json");
45   
46            List<NameValuePair> params = new ArrayList<NameValuePair>();
47            params.add(new BasicNameValuePair("serviceClassName", "com.liferay.portlet.documentlibrary.service.DLFileEntryServiceUtil"));
48            params.add(new BasicNameValuePair("serviceMethodName", "getFileAsStream"));
49            params.add(new BasicNameValuePair("serviceParameters", "[fileEntryId,version]"));
50            params.add(new BasicNameValuePair("fileEntryId", "11718"));
51            params.add(new BasicNameValuePair("version", "1.0"));       
52            UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, "UTF-8");
53            post.setEntity(entity);
54   
55            HttpResponse resp = httpclient.execute(targetHost, post, ctx);
56            
57            try
58            {
59                File f = new File("outFile.java");
60                OutputStream out = new FileOutputStream(f);
61                resp.getEntity().writeTo(out);
62                out.close();
63                System.out.println("Fichero creado ...................................");
64            } catch (IOException e) {
65                System.out.println("Error al crear el fichero: " + e.getMessage());
66            }
67            
68            httpclient.getConnectionManager().shutdown();
69        }
70    }


What's wrong? All files downloaded with 0 bytes

I use Liferay 6.1 CE GA1

Thanks!

Alfonso
Roshan Qureshi
RE: Get File object from DocumentLibrary.
18 aprile 2012 0.50
Risposta

Roshan Qureshi

Punteggio: Regular Member

Messaggi: 144

Data di Iscrizione: 24 agosto 2010

Messaggi recenti

Liferay 5.2 also having the same class
DLFileEntryLocalServiceUtil which can be used to get the inputStream.

Participate in the State of Liferay Community 2017. Help the community and even win some prizes!