on 09-18-2007 10:32 PM
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
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 :
Regards
Abhijith YS
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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...
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
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>Preferences>Java>Code Generation>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
Thank you for all Eray,
I was able to solve the problem
Https: / / www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/km 2bLibrary%%% 2b-2bReusable% 2bComponent% 2bfor% 2bWebDynpro% 2bJava
Thanks again
Hi,
Please tell me how to upload file from local machine.
I have successfully uploaded files by using File Upload UI element where I am able to select the required file.
Now I have a requirement of picking up a file from desktop using the code.
If I am simply giving the path "C:
Folder\file.txt", it is searching on server.
Thanks!!
Anubha
User | Count |
---|---|
85 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.