cancel
Showing results for 
Search instead for 
Did you mean: 

How to Resize image file in Java Webdynpro

former_member182205
Participant
0 Kudos

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..

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos
former_member182205
Participant
0 Kudos

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

junwu
Active Contributor
0 Kudos

resizing is pure java, nothing to do with web dynpro

Former Member
0 Kudos

Hi

I dont want to say anything about this thread. Please just check your Java knowledge.

Amey-Mogare
Contributor
0 Kudos

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.");					
}

former_member182205
Participant
0 Kudos

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.