Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X
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).
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
Solved! Go to Solution.
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
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.