Forums de discussion

Get a File object from a DLFileEntry

thumbnail
Pierre Henri, modifié il y a 13 années.

Get a File object from a DLFileEntry

New Member Publications: 11 Date d'inscription: 04/12/09 Publications récentes
Hello,

I need a small help with the Liferay SDK.

I have a DLFileEntry object, and i want to have the linked File object (or the complete path of the file, it's in relation).

Anybody could give me idea to do this ?
Thank you
thumbnail
Corné Aussems, modifié il y a 13 années.

RE: Get a File object from a DLFileEntry

Liferay Legend Publications: 1313 Date d'inscription: 03/10/06 Publications récentes
Hope this helps ;
	public InputStream getFileAsInputStream(final long fileEntryId) throws VDNassert {

		InputStream result = null;

		try {
			DLFileEntry dlEntry = getFile(fileEntryId);

			result = DLFileEntryLocalServiceUtil.getFileAsStream(dlEntry.getCompanyId(), dlEntry.getUserId(), dlEntry
					.getFolderId(), dlEntry.getName(), dlEntry.getVersion());
		} catch (Exception e) {
			logger.error("getFileAsInputStream(long)", e); //$NON-NLS-1$
			VDNassert.always(e.getMessage());
		}

		return result;
	}
thumbnail
jelmer kuperus, modifié il y a 13 années.

RE: Get a File object from a DLFileEntry

Liferay Legend Publications: 1191 Date d'inscription: 10/03/10 Publications récentes
There is no easy way to get a reference to the file on disk. And you probably should not attempt to get one. Liferay abstracts away the way a file is stored via the Hook interface. This allows you to easily switch between storing your files on a file system and for instance storing your files on amazon s3.

Depending on your needs Corne's solution might be the way to go. I have no idea what a VDNassert is though emoticon
thumbnail
Rob Chan, modifié il y a 12 années.

RE: Get a File object from a DLFileEntry

Junior Member Publications: 82 Date d'inscription: 23/03/11 Publications récentes
I'm quite interested in why this is the case. What is the point of being able to add a file to the document library and be unable to access the file programatically?
thumbnail
jelmer kuperus, modifié il y a 12 années.

RE: Get a File object from a DLFileEntry

Liferay Legend Publications: 1191 Date d'inscription: 10/03/10 Publications récentes
Because documents in the document library do not have to be stored on a file system.
When you use amazon s3 to serve the files in your document library, you are storing files on a remote machine, and accessing them via http calls.

File would not fit
thumbnail
Rob Chan, modifié il y a 12 années.

RE: Get a File object from a DLFileEntry

Junior Member Publications: 82 Date d'inscription: 23/03/11 Publications récentes
From what I can surmise amazon S3 is an entirely different product/service that requires you to purchase a subscription.

I'm currently able to host files onto my DL without using amazon's product. What I'm really interested in, is why you can use the GUI to upload and download files onto and fromthe document library, but be completely unable to do these same functions in code.

Where are the documents in the DL being stored if not on the file system?
thumbnail
Corné Aussems, modifié il y a 12 années.

RE: Get a File object from a DLFileEntry

Liferay Legend Publications: 1313 Date d'inscription: 03/10/06 Publications récentes
This completely depends on your choosen implementation

See portal.properties

##
## Document Library Portlet
##

    #
    # Set the name of a class that implements
    # com.liferay.documentlibrary.util.Hook. The
    # document library server will use this persist documents.
    #
    #dl.hook.impl=com.liferay.documentlibrary.util.AdvancedFileSystemHook
    #dl.hook.impl=com.liferay.documentlibrary.util.CMISHook
    dl.hook.impl=com.liferay.documentlibrary.util.FileSystemHook
    #dl.hook.impl=com.liferay.documentlibrary.util.JCRHook
    #dl.hook.impl=com.liferay.documentlibrary.util.S3Hook


By default this will be the FileSystemHook which saves your documents on the Filesystem

But could as easilly be as Jelmer describes a AmazonS3 repository;
Or better your own Implementation
thumbnail
Hitoshi Ozawa, modifié il y a 12 années.

RE: Get a File object from a DLFileEntry

Liferay Legend Publications: 7942 Date d'inscription: 24/03/10 Publications récentes
I'm currently able to host files onto my DL without using amazon's product. What I'm really interested in, is why you can use the GUI to upload and download files onto and fromthe document library, but be completely unable to do these same functions in code.


This may be is a little bit different from what's you're trying to do, but you can use the WebDAV interface or web service interface to upload/download files from Document Library(You can search this site and Internet on how to do this).

Liferay generates index on uploaded files and set permissions, so uploading to the Document Library is just a matter of outputting byte stream on to a hard disk.