on 05-25-2011 6:34 AM
Hi,
I have a requirement, where user can upload his/her image from his desktop into webdynpro java screen. and suppose he uploads his image and when he refreshed the page or again logins, he should see his image which he uploaded last time.
So what I am doing is when user is uploading his image, first I am saving his image into some folder in portal server, and I am reding that image from that folder.
for this I have created, 1 folder in portal server with name Image, and I am saving all the images which user is uploading.
This is the code I am using.
IWDResource resource = null;
WDWebResourceType resourceType = null;
File fp = new File("/usr/sap/Image/"UserID".jpg");
FileInputStream fis = new FileInputStream(fp);
BufferedInputStream bis = new BufferedInputStream(fis);
resourceType =
WDWebResourceType.getWebResourceType("",
"JPG");
resource = WDResourceFactory.createResource(bis, UserID+".jpg",resourceType, true);
if(resource!=null)
{
wdContext.currentResourceElement().setImgURL(resource.getUrl(WDFileDownloadBehaviour.OPEN_INPLACE.ordinal()));
}else
{
wdContext.currentResourceElement().setImgURL("");
wdComponentAPI.getMessageManager().reportSuccess("Please upload your passport size photograph here");
}
My question is : How I can resize the pic size before saving to Image folder, that is suppose user is uploading 1 MB size photo, but i want to resize it to say 15 KB only before saving to Image folder in portal server. I want to restrict all the image size to 15 KB only.
How to do that in the above code? please help..Thanks..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Erhan,
I want java webdynpro code, the code you gave is purely java one, in my project i am using webdynpro UI element , IMAGE, and how i will use the code given by you in that context .
please help me with java webdynpro code where Image UI element is used.
Thanks..
Edited by: User Satyam on May 29, 2011 7:05 AM
Hi,
You can check file size before uploading to Portal KM.
Following code may help: -
IWDResource fileResource = wdContext.currentContextElement().getPhoto();
String fileName = fileResource.getResourceName();
String fileExtension = fileResource.getResourceType().getFileExtension();
if ( ! fileExtension.equalsIgnoreCase("jpg")) {
myMessage.reportException("Only .jpg or .jpeg files are supported !!!");
}
InputStream stream = fileResource.read(false);
long fsize = stream.available();
int maxSize = 102400; //100Kb
if (fsize > maxSize){
long kbSize = fsize / 1024;
myMessage.reportException("Maximum size of uploaded file should be 100 Kb. Your File size is: "+kbSize+" Kb.");
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi AMey,
Thanks for the reply but I am not asking how to check the file size , what I want is even in case user uploads 1 MB file for example, I want to resize it to say 15 KB programatically in my java web dynpro code and than save it to some folder in portal server .
How to resize the file programatically in my java web dynpro code This is my question.
User | Count |
---|---|
95 | |
11 | |
11 | |
10 | |
9 | |
8 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.