Foren

Message Board - Attachment

Ady Das OToole, geändert vor 16 Jahren.

Message Board - Attachment

New Member Beiträge: 5 Beitrittsdatum: 09.04.07 Neueste Beiträge
I'm in the process of migrating from a legacy forum to Lifery MB and have a question about Attachment storage.

Anyone know how Attachments are stored - more specifically where is the mapping between the Post (in MBMessage, Demoticon and the Attachment (In the File system) stored?
thumbnail
Jerry Niu, geändert vor 16 Jahren.

RE: Message Board - Attachment

Expert Beiträge: 451 Beitrittsdatum: 21.06.06 Neueste Beiträge
The files are stored in the Doc Lib, here's the code that does it:

MBMessageLocalServiceUtil/Impl::addMessage

		// File attachments

		if (files.size() > 0) {
			long companyId = message.getCompanyId();
			String portletId = CompanyImpl.SYSTEM_STRING;
			long groupId = GroupImpl.DEFAULT_PARENT_GROUP_ID;
			String repositoryId = CompanyImpl.SYSTEM_STRING;
			String dirName = message.getAttachmentsDir();

			try {
				try {
					DLServiceUtil.deleteDirectory(
						companyId, portletId, repositoryId, dirName);
				}
				catch (NoSuchDirectoryException nsde) {
				}

				DLServiceUtil.addDirectory(companyId, repositoryId, dirName);

				for (int i = 0; i < files.size(); i++) {
					ObjectValuePair ovp = (ObjectValuePair)files.get(i);

					String fileName = (String)ovp.getKey();
					byte[] byteArray = (byte[])ovp.getValue();

					try {
						DLServiceUtil.addFile(
							companyId, portletId, groupId, repositoryId,
							dirName + "/" + fileName, byteArray);
					}
					catch (DuplicateFileException dfe) {
					}
				}
			}
			catch (RemoteException re) {
				throw new SystemException(re);
			}
		}
Ady Das OToole, geändert vor 16 Jahren.

RE: Message Board - Attachment

New Member Beiträge: 5 Beitrittsdatum: 09.04.07 Neueste Beiträge
Thanks but how does the MBMessage row store the path to the file? I see the boolean indicating that an attachment exists but cannot see the file path stored. Does it retrieve the file from the Doc Lib some other way?
thumbnail
Rushi Priya Panda, geändert vor 8 Jahren.

RE: Message Board - Attachment

New Member Beiträge: 5 Beitrittsdatum: 19.01.11 Neueste Beiträge
Currently attachments are stored something like below.

document_library/<company id>/0/messageboards/<thread id>/<message id>

So when attachments are created, they are places inside the folder name created by name of the message id of the message. You can see the code in below class.

The code for this is in "portal-impl/src/com/liferay/portlet/messageboards/model/impl/MBMessageImpl.java".

And while rendering, it get retrieved like below.

existingAttachments = DLStoreUtil.getFileNames(message.getCompanyId(), CompanyConstants.SYSTEM, message.getAttachmentsDir());

message.getAttachmentsDir() =" document_library/<company id>/0/messageboards/<thread id>/<message id>"