[opencms-dev] How can i put pdf or jpg files in OpenCMS from Java??

Florian Hopf hopf at synyx.de
Fri Mar 6 13:38:20 CET 2009


Hi,

José Manuel Prada Sierra wrote:
> I have a java class that create contents in opencms and it's ok, but and
> i need put jpg or pdf files in opencms and it's no ok.
> I have an url with the address of a jpg or pdf file.
> I have to download the file and put it into opencms using java but i
> don't know

If the file is on a remote server you can mybe retrieve it using
httpclient library. If it is a local file you can just open it using
standard java mechanisms.

In any case you have to write the contents of the file to a byte array,
then you can use this method to create the file:
http://api.synyx.de/opencms_7.0.4/org/opencms/file/CmsObject.html#createResource(java.lang.String,%20int,%20byte[],%20java.util.List)

Just pass in the resource type id for binary or image, you can get these
from static methods in the resource type classes, e.g.
http://api.synyx.de/opencms_7.0.4/org/opencms/file/types/CmsResourceTypeBinary.html#getStaticTypeId()

HTH
Flo



More information about the opencms-dev mailing list