Foren

Using and accessing File Upload field within a custom metadata set

Eric Smith, geändert vor 9 Jahren.

Using and accessing File Upload field within a custom metadata set

Junior Member Beiträge: 66 Beitrittsdatum: 28.08.12 Neueste Beiträge
I created a custom metadata set with a File Upload field and added it to a document type. Now I've created an instance of the document type, and I would like to use the file in the metadata set. However, I can't figure out how to nicely link to the document as well as access the document. I know the type is ddm-fileupload and the data type is file-upload. How do I:
- Get the URL to the file?
- Access the actual file?

Here's the groovy code I used to do a POC:
-------------------------------------------------------------------------
import com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil;
import com.liferay.portlet.documentlibrary.model.DLFileEntry;
import com.liferay.portlet.documentlibrary.model.DLFileVersion;
import com.liferay.portlet.dynamicdatamapping.storage.Fields;

//706402 or 710401 - IDs of file entries of the desired document type
DLFileEntry fileEntry = DLFileEntryLocalServiceUtil.getDLFileEntry(710401);

Map<String,Fields> fieldsMap = fileEntry.getFieldsMap(fileEntry.getLatestFileVersion(true).getFileVersionId());

for (String fieldsName: fieldsMap.keySet()) {
Fields fields = fieldsMap.getAt(fieldsName);
Set<String> fieldNames = fields.getNames();

for(String fieldName: fieldNames) {
if (fields.get(fieldName).getType().equals("ddm-fileupload")) {
out.println("Value:"+ fields.get(fieldName).getValue());
// ADD SOMETHING HERE
}
}
}

-------------------------------------------------------------------------
Thanks
Sakshi Batra, geändert vor 8 Jahren.

RE: Using and accessing File Upload field within a custom metadata set

New Member Beiträge: 21 Beitrittsdatum: 27.05.14 Neueste Beiträge
Hi

Have you got the solution?

I am also looking for similar kind of thing.

Regards,
Sakshi
Eric Smith, geändert vor 8 Jahren.

RE: Using and accessing File Upload field within a custom metadata set

Junior Member Beiträge: 66 Beitrittsdatum: 28.08.12 Neueste Beiträge
No, I never did figure this out. Post if you figure it out, I'm still interested in a solution.