16 Replies Latest reply: Sep 24, 2010 12:38 PM by Priya Mudda RSS

File Upload to KM

Eray Ince
Currently Being Moderated

Hello Friends;

I want to develop a portal j2ee aplication. And user can upload file to KM and can download it.

How can i do it using KM?

Can you offer me a blog, pdf, etc.

 

Thanks in Advance

Best Regards

  • Re: File Upload to KM
    Abhijith YS
    Currently Being Moderated

    Hi

     

    Blogs

    1 . /people/rohit.radhakrishnan/blog/2005/05/27/uploading-files-to-km-repository-using-webdynpro-apis

    2 . /people/bobu.georgeputheeckal/blog/2006/12/22/getting-an-image-from-km-documents-to-be-used-in-web-dynpro

     

    Code samples :

    1. https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/62fde490-0201-0010-6fb8-c3b34d0f6772

    2. https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/75336f09-0801-0010-4ea6-90ca92e98b28

    3. https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/e79ee490-0201-0010-ddaa-e4e6a55e7100

     

     

    Regards

    Abhijith YS

    • Re: File Upload to KM
      Eray Ince
      Currently Being Moderated

      Hi...

      Thanks for your reply...

      can these blogs adapted to j2ee projects?

       

      Best Regards

    • Re: File Upload to KM
      Eray Ince
      Currently Being Moderated

      Hello Again;

      <b>IWDClientUser wdClientUser = WDClientUser.getCurrentUser();</b>

      IUser sapUser = wdClientUser.getSAPUser();

      com.sapportals.portal.security.usermanagement.IUser ep5User =

                      WPUMFactory.getUserFactory().getEP5User(sapUser);

       

      I couldnt use bold line in j2ee project. this line related the blogs link.

      If i use<b> com.sap.security.api.IUser sapUser  =                                                                                UMFactory.getAuthenticator().getLoggedInUser();</b>

      instead of above line, nwds gives me deprecated error.

      What should i do?

      Thanks

      Best Regards

      • Re: File Upload to KM
        Abhijith YS
        Currently Being Moderated

        Hi

         

        Right click on your error line, go to source, add imports, try with what are the imports you can make.

         

        Regards

        Abhijith YS

        • Re: File Upload to KM
          Eray Ince
          Currently Being Moderated

          Hi;

          I am telling about j2ee application. IWDClientUser is webdynpro component, right?

          if it is not, how can i import it? Because if i click error line i get this <a href="http://erayince.com/KM.jpg">error</a>

          Please help...

          Best Regards

          • Re: File Upload to KM
            Abhijith YS
            Currently Being Moderated

            Hi

            Try with this

            import com.sap.tc.webdynpro.services.sal.um.api.WDClientUser;

             

            WDClientUser wdClientUser =(WDClientUser) wdClientUser.getCurrentUser();

             

            Regards

            Abhijith YS

            • Re: File Upload to KM
              Eray Ince
              Currently Being Moderated

              Sorry for too many questions.

              I have added <b>_webdynpro_services.jar</b> to project.

              if i <b>import com.sap.tc.webdynpro.services.sal.um.api.WDClientUser</b>; line

              it is ok. But after i add this line

              <b>IWDClientUser wdClientUser = WDClientUser.getCurrentUser(); </b>

              it is ok too. However if i build web archieve i get following error.

              <b>

              This compilation unit indirectly references the missing type com.sap.exception.BaseException (typically some required class file is referencing a type outside the classpath)</b>

               

              Thanks Again...

              • Re: File Upload to KM
                Eray Ince
                Currently Being Moderated

                I have solved problem. There is bug on blog. The code must be

                try{
                com.sap.security.api.IUser sapUser = com.sap.security.api.UMFactory.getAuthenticator().forceLoggedInUser(request,response);
                sapUser.getAccessibilityLevel();
                com.sapportals.portal.security.usermanagement.IUser ep5User = 
                com.sapportals.wcm.util.usermanagement.WPUMFactory.getUserFactory().getEP5User(sapUser);
                
                ResourceContext context = new ResourceContext(ep5User);
                /*Give the path to KM in the variable path */
                RID rid = RID.getRID("/documents/DENEME");
                IResourceFactory factory = ResourceFactory.getInstance();
                ICollection folder = (ICollection) factory.getResource(rid,context); 
                String location = "E:\DynproTempFolder\";
                String fileName = location+"a.pdf";
                File file = new File(fileName);
                
                // IResource res_forMap = ResourceFactory.getInstance().getResource(rid, context);
                // IPropertyMap pm = res_forMap.getProperties();
                
                String mime = new MimetypesFileTypeMap().getContentType(file);
                
                
                /*Create an output stream for writing to the temperory location*/ 
                /*From the temporary location read the file using an input stream*/
                
                FileInputStream fin = new FileInputStream(fileName);
                // fin.read();
                
                /*Using this input stream we can write to the repository
                Content content = new Content(fileelement.getFiledata(),fileelement.get) */
                
                
                Content content = new Content(fin,"byte", -1L);
                
                IResource newResource = folder.createResource("a.pdf",null,content);
                
                
                fin.close();
                //file.delete(); 

                 

                 

                fin.read() line is read only one character from file, so if file pdf,image, even word document, file content is damaged.

                 

                Message was edited by:

                        Eray

                • Re: File Upload to KM
                  Sumant Mujumdar
                  Currently Being Moderated

                  Hi Eray,

                   

                  Could you post the complete code. I am getting an error for

                  ...... forceLoggedInUser(request,response);

                   

                  request & response - "The field request is not visible".

                   

                  Regards

                  Sumant

                  • Re: File Upload to KM
                    Eray Ince
                    Currently Being Moderated

                    Here is the code...

                    If it helps you, please reward good point.

                    Best Regards

                    ERAY

                     

                     

                    package util;
                    import java.io.File;
                    import java.io.FileInputStream;
                    
                    import javax.activation.MimetypesFileTypeMap;
                    import javax.servlet.http.HttpServletRequest;
                    import javax.servlet.http.HttpServletResponse;
                    
                    import com.sapportals.htmlb.page.DynPage;
                    import com.sapportals.htmlb.page.PageException;
                    import com.sapportals.portal.htmlb.page.PageProcessorComponent;
                    import com.sapportals.portal.prt.component.IPortalComponentInitContext;
                    import com.sapportals.portal.prt.component.IPortalComponentRequest;
                    import com.sapportals.portal.prt.component.IPortalComponentResponse;
                    import com.sapportals.wcm.repository.Content;
                    import com.sapportals.wcm.repository.ICollection;
                    import com.sapportals.wcm.repository.IResource;
                    import com.sapportals.wcm.repository.IResourceFactory;
                    import com.sapportals.wcm.repository.ResourceContext;
                    import com.sapportals.wcm.repository.ResourceFactory;
                    import com.sapportals.wcm.util.uri.RID;
                    
                    /**
                     * @author Tyler
                     *
                     * To change the template for this generated type comment go to
                     * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
                     */
                    public class UploadKM extends PageProcessorComponent {
                         public static class Internal extends DynPage {
                    
                              public String SendToKM(String KM_File, String KM_path, HttpServletRequest req, HttpServletResponse res) throws Exception {
                                   IPortalComponentRequest request =
                                        (IPortalComponentRequest) this.getRequest();
                                   IPortalComponentResponse response =
                                        (IPortalComponentResponse) this.getResponse();
                                   try{
                                        com.sap.security.api.IUser sapUser = com.sap.security.api.UMFactory.getAuthenticator().forceLoggedInUser(req,res);
                                        sapUser.getAccessibilityLevel();
                                        
                                        com.sapportals.portal.security.usermanagement.IUser ep5User = 
                                                  com.sapportals.wcm.util.usermanagement.WPUMFactory.getUserFactory().getEP5User(sapUser);
                                        
                                         ResourceContext context = new ResourceContext(ep5User);
                                        /*Give the path to KM in the variable path */
                              
                                         RID rid = RID.getRID(KM_path);
                                         
                                   //     RID rid = RID.getRID("/documents/DENEME");
                                        
                                         IResourceFactory factory = ResourceFactory.getInstance();
                                         ICollection folder = (ICollection) factory.getResource(rid,context); 
                                         String location = "E:\\DynproTempFolder\\DynproTempFolder2\\";
                                         String fileName = location+KM_File;
                                         File file = new File(fileName);
                    
                                         String mime = new MimetypesFileTypeMap().getContentType(file);
                                        
                                        /*Create an output stream for writing to the temperory location*/      
                                        /*From the temporary location read the file using an input stream*/
                                        
                                         FileInputStream fin = new FileInputStream(fileName);
                                   //      fin.read();
                                        
                                        /*Using this input stream we can write to the repository
                                         Content content = new Content(fileelement.getFiledata(),fileelement.get) */
                                         
                                        
                                         Content content = new Content(fin,"byte", -1L);
                                        
                                         IResource newResource = folder.createResource(KM_File,null,content);
                                        
                                         
                                         fin.close();
                                        //file.delete(); 
                                        return "OK";
                                        
                                   } catch (Exception ex) {
                                        return ex.getMessage();
                                   }
                              }
                    
                              /* (non-Javadoc)
                               * @see com.sapportals.htmlb.page.DynPage#doInitialization()
                               */
                              public void doInitialization() throws PageException {
                                   // TODO Auto-generated method stub
                    
                              }
                    
                              /* (non-Javadoc)
                               * @see com.sapportals.htmlb.page.DynPage#doProcessAfterInput()
                               */
                              public void doProcessAfterInput() throws PageException {
                                   // TODO Auto-generated method stub
                    
                              }
                    
                              /* (non-Javadoc)
                               * @see com.sapportals.htmlb.page.DynPage#doProcessBeforeOutput()
                               */
                              public void doProcessBeforeOutput() throws PageException {
                                   // TODO Auto-generated method stub
                    
                              }
                         }
                    
                         /* (non-Javadoc)
                          * @see com.sapportals.portal.htmlb.page.PageProcessorComponent#getPage()
                          */
                         public DynPage getPage() {
                              // TODO Auto-generated method stub
                              return null;
                         }
                    
                         /* (non-Javadoc)
                          * @see com.sapportals.portal.prt.component.IPortalComponentInit#init(com.sapportals.portal.prt.component.IPortalComponentInitContext)
                          */
                         public void init(IPortalComponentInitContext arg0) {
                              // TODO Auto-generated method stub
                    
                         }
                    }
                    

                     

                    Edited by: Eray on Feb 19, 2008 4:25 PM

                  • Re: File Upload to KM
                    Francesc Balagué
                    Currently Being Moderated

                    Hello Eray,

                     

                    I have a problem in your perhaps I can help, thanks in advance.

                     

                    As I call SendToKM within my WebDynpro?

                     

                    in my WebDynpro don't exist request and response...

Actions