cancel
Showing results for 
Search instead for 
Did you mean: 

size check photoupload

Former Member
0 Kudos

Hi I want to upload an image to a server but before i do that I want to check if the filesize is not bigger then 250 kb and the image not bigger 113 x 155 pixels. how can i build it in in this code?

IWDMessageManager manager = wdComponentAPI.getMessageManager();

boolean result = false;

try

{

IRequest_OS_007_IMAGE_UPLOAD_OS_007_IMAGE_UPLOADElement eService = wdContext.currentRequest_OS_007_IMAGE_UPLOAD_OS_007_IMAGE_UPLOADElement();

eService.setFOTO(foto);

eService.setPERSONEELSNUMMER(pernr);

eService.modelObject()._setHTTPDestinationName(wdThis.wdGetWebserviceUtilsInterface().getHTTPDestination("OS_007_IMAGE_UPLOAD"));

eService.modelObject()._setEndPoint(wdThis.wdGetWebserviceUtilsInterface().getEndPoint("OS_007_IMAGE_UPLOAD"));

eService.modelObject().execute();

wdContext.nodeResponse().invalidate();

if (wdContext.nodeResponse().size() == 1)

{

result = wdContext.currentResponseElement().getResult();

}

}

catch(Exception e)

{

manager.reportException(e.getMessage(), false);

}

return result;

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

let your context attribute of type resource is FileUPloadUI,

write this code to check Dimensions

FileInputStream ss=(FileInputStream)wdContext.currentContextElement().getFileUploadUI().read(false);
java.awt.image.BufferedImage img=javax.imageio.ImageIO.read(ss);
if(img.getHeight()>135 &&img.getWidth()<135){
// do your code here
}

to check size of the file

InputStream stream =wdContext.currentContextElement().getFileUploadUI().read(false);
int size = stream.available();
if(size<250*1048576){
// do code here
}

regards,

Naga

Former Member
0 Kudos

what you mean by this?

let your context attribute of type resource is FileUPloadUI,

don't have aype called resource

Former Member
0 Kudos

Hi,

are you using fileupload UI element?, if yes you need to bind resource property to a context attribute of type com.sap.ide.webdynpro.uielementdefinitions.Resource.

I just name that attribute to "FileUploadUI".

Regards,

Naga

Former Member
0 Kudos

FileInputStream what is this for a type? java. io?

Former Member
0 Kudos

java.io.InputStream

Regards,

Naga

Former Member
0 Kudos

I get now for FileUploadUI the error message unhandled exception type ioexception

could it be because my data type property has a binairy type connected to it?

Former Member
0 Kudos

Hi,

Simply select the code right click and select surround with try catch block.

which one you used for file upload property binding data or resource.

Regards,

Naga

Former Member
0 Kudos

source is ui

data is biniaty type

Former Member
0 Kudos

code I have now stil doesn't work. what am i doing wrong

try {

FileInputStream ss=(FileInputStream)wdContext.currentContextElement().getFileUploadUI().read(false);

java.awt.image.BufferedImage img=javax.imageio.ImageIO.read(ss);

if(img.getHeight()>155 &&img.getWidth()<115){

}

} catch (IOException e) {

// TODO Auto-generated catch block

// e.printStackTrace();

String[] msg = {""};

manager.reportMessage(IMessageEssentGidsComp.PHOTO__SIZE__TO__LARGE, msg, false);

}

try {

InputStream stream =wdContext.currentContextElement().getFileUploadUI().read(false);

int size = stream.available();

if(size<250*1048576){

}

} catch (IOException e) {

// TODO Auto-generated catch block

// e.printStackTrace();

String[] msg = {""};

manager.reportMessage(IMessageEssentGidsComp.PHOTO__TOO__LARGE, msg, false);

}

Former Member
0 Kudos

Hi,

This Code Will work when use an attribute of type resource.

instead of this

// create a temporary file

FileInputStream ss=(FileInputStream)wdContext.currentContextElement().getFileUploadUI().read(false);

write this code

After getting the byte[].

File f=new File(file);
FileOutputStream fos=new FileOutputStream(f);
fos.write(byteArray);
fos.close();

FileInputStream ss=new FileInputStream(f);
java.awt.image.BufferedImage img=javax.imageio.ImageIO.read(ss);
if(img.getHeight()>155 &&img.getWidth()<115){
String[] msg = {""};
manager.reportMessage(IMessageEssentGidsComp.PHOTO__SIZE__TO__LARGE, msg, false);


} 

int size = stream.available();
if(size<250*1048576){
String[] msg = {""};
manager.reportMessage(IMessageEssentGidsComp.PHOTO__TOO__LARGE, msg, false);
}


f.delete();

Regards,

Naga

Former Member
0 Kudos

I've an attribute of type resource. how does it look then

Former Member
0 Kudos

when I use this code I get for file, byteArray and stream that file can not be resolved, what can it be?

if (this.uploadImage())

{

// FileInputStream ss=(FileInputStream)wdContext.currentContextElement().getFileUploadUI().read(false);

try

{

File f=new File(file);

FileOutputStream fos=new FileOutputStream(f);

fos.write(byteArray);

fos.close();

FileInputStream ss=new FileInputStream(f);

java.awt.image.BufferedImage img=javax.imageio.ImageIO.read(ss);

if(img.getHeight()>155 &&img.getWidth()<115){

String[] msg = {""};

manager.reportMessage(IMessageEssentGidsComp.PHOTO__SIZE__TO__LARGE, msg, false);

}

int size = stream.available();

if(size<250*1048576){

String[] msg = {""};

manager.reportMessage(IMessageEssentGidsComp.PHOTO__TOO__LARGE, msg, false);

}

wdThis.wdGetEssentGidsCompController().ImageUpload();

f.delete();

}

catch (Exception e)

{

manager.reportException("highlightLocation:" + e.getLocalizedMessage(), false);

}

}

regards

Former Member
0 Kudos

Hi Dresen,

that was java.io.File

Please provide your mail id : i will send the sample proj to you.

Regards,

Naga

Answers (0)