cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

How to get physical file size from an EPMDocument using Java code?

PeterWigren
12-Amethyst

How to get physical file size from an EPMDocument using Java code?

Hello!

Does anyone happen to know how to get the file size of an EPMDocument or more precise the file size of the primary content?

I'm looking for the value presented under the Content Tab -> File Size for a particual version (see embedded image).

EPMDocument_file_size.JPG

I would like to extract this value using Java.

Pseudo code below:

EPMDocument doc = getEPMDocument("filename", "1", "3");

String size = doc.getPrimaryContentSize();

Thank you for your effort!

/Peter

ACCEPTED SOLUTION

Accepted Solutions

Hello Patrick!

Thanks for the suggestion!

I tried the code you provided but sadly ContentHelper.getPrimary(doc); returns null.

So I played about with the API a little further and finally I got it to work using below code:

ObjectReference or = ObjectReference.newObjectReference(doc);

ContentItem contentItem = ContentHelper.service.getPrimaryContent(or);

if (contentItem instanceof ApplicationData) { // as opposed to ExternalData or URLData

sizeInKb = ((ApplicationData) contentItem).getFileSizeKB();

}

Cheers!

/Peter

View solution in original post

3 REPLIES 3

Checkout the wt.content package in Foundation.

I think you want something like this.

import wt.content.*

...

EPMDocument doc = ...

ContentItem contentItem = ContentHelper.getPrimary(doc);

float sizeInKb = 0;

if (contentItem instanceof ApplicationData) { // as opposed to ExternalData or URLData

sizeInKb = ((ApplicationData)contentItem).getFileSizeKB();

}

I haven't tried it and I'm not sure if these methods are supported and it might be more efficient to write some query but this seems reasonable.

Hello Patrick!

Thanks for the suggestion!

I tried the code you provided but sadly ContentHelper.getPrimary(doc); returns null.

So I played about with the API a little further and finally I got it to work using below code:

ObjectReference or = ObjectReference.newObjectReference(doc);

ContentItem contentItem = ContentHelper.service.getPrimaryContent(or);

if (contentItem instanceof ApplicationData) { // as opposed to ExternalData or URLData

sizeInKb = ((ApplicationData) contentItem).getFileSizeKB();

}

Cheers!

/Peter

Using ContentHelper.service.getPrimaryContent is the right way. I was assuming ContentHelper.getPrimary was a shortcut to that method, but I was wrong. I am glad it is working for you.

Announcements


Top Tags