jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mila Yuliani <mila.yuli...@meruvian.org>
Subject How to upload image from jackrabbit
Date Wed, 14 Apr 2010 01:23:26 GMT
Hi all,

I have problem of my jackrabbit..:(
i'm new in jackrabbit for upload and display content. i'm using velocity for
view from client. my case is for upload photo and display photo from
repository node jcr. here the code :

 1. formRegister.vm :
               <td width="25%" height="26" align="right"
class="tdleft">Upload Photo :&nbsp;&nbsp;</td>
               <td class="tdright">&nbsp;&nbsp;<input type="file" size="23"
name="docUpload" value="$!employee.docUpload"></td>

 2. class Pojo is named Employee.java :
     private String docUpload="";
     private String docUploadName="";
     private String docUploadPath="";

 3. SaveEmployee.java for saving into database and repository jcr :
     private File docUpload;
     private String docUploadFileName;
    private String docUploadContentType;

     public String execute(){
              if(docUpload != null) {
                 try {
docUpload, getId());
                 } catch (RepositoryException e) {
                 } catch (IOException e) {

 4. this RepositoryDao for Data Access Object Jackrabbit:

      public void importFile(Node parentnode, File file, String key) throws
RepositoryException, IOException {
         String mimeType = new MimetypesFileTypeMap().getContentType(file);
         if (mimeType==null) mimeType="application/octet-stream";

         Node fileNode = parentnode.addNode(key, "nt:file");

         Node resNode = fileNode.addNode("jcr:content", "nt:resource");
         resNode.addMixin("mix:versionable"); //set node mixin type
         //resNode.setProperty("jcr:versionLabels", file.getName());
         resNode.setProperty("jcr:mimeType", mimeType);
         resNode.setProperty("jcr:encoding", "");
         resNode.setProperty("jcr:data", new FileInputStream(file));
         Calendar lastModified = Calendar.getInstance();
         resNode.setProperty("jcr:lastModified", lastModified);


    public void save()
     throws AccessDeniedException, ItemExistsException,
            InvalidItemStateException, VersionException, LockException,
            NoSuchNodeTypeException, RepositoryException {

 5. here is from database :
 DocUploadName : screenshot-2.png
 DocUploadPath   :

 that's mean is data has upload successfully into database, right?
 so, how i can get image name from docUploadName and it's from repository
node jackrabbit.

 Correct me if I'm wrong..:)

Best Regards,

Mila Yuliani
Developer Blueoxygen Workspace
Meruvian - Indonesia
Office Phone : (021)935 865 77
Mobile : 02199869875

View raw message