cancel
Showing results for 
Search instead for 
Did you mean: 

making uploaded picture visible

Former Member
0 Kudos

Hi, I made an application after "Uploading and Downloading Files in Web Dynpro Java" tutorial. I upload a picture which is stocked in ImageContext. How do I project uploaded Image right after it was uploaded, dont want any actions beetween.

1. I press Upload, it uploads image to "ImgaeContext"

2. It displays itseld in the ImageChild (or other) area.

I tried just link to the "resource" option at Image Child my ImageContext where image is stored but It cant be done. Any Idea how can this be done? Regards.

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member182598
Active Contributor
0 Kudos

Hi Balmer,

Here I assume that you are working with the File Upload Download tutorial provided at SDN. If not make necessary changes in the variable names and methods wherever applicable.

Create a ValueElement ImageSource of type String in your File Upload View.

Create an Image UI Element and add the bind the source property of it to the ImageSource attribute.

Add the following lines in in the onActionUploadFile()

IWDCachedWebResource re=WDWebResource.getWebResource(file,WDWebResourceType.JPG_IMAGE);

try

{

element.setImageSource(re.getURL());

}

catch(Exception ex)

{

wdComponentAPI.getMessageManager().reportException(ex.getLocalizedMessage(),false);

}

Please note that I have hardcoded the WDWebResource Type as JPG Image.

You can apply switch-case on the file extension for proper web resource.

After you upload a .jpeg file it will be visible.

Do let me know if you face any issues.

xxxxxxxxxxxxxxxx

Thanks

Prashant

Edited by: Armin Reichert on Feb 23, 2008 6:28 PM

Former Member
0 Kudos

Hello, thank you for the answer.

Ive got problem with "file", it cannot be resolved. Tried to link it to getFileName() then but it cant be done that way, types missmatch. Once I linked it to empty method or parameter still could not be resolved by Netweaver. I did import com.sap.tc.webdynpro.services.sal.url.api.*; Contexts and UI parts are named exactly same as in the Tutorial.

I see in documentation that right syntax for this is

getWebResource(WDDeployableObjectPart deployableObjectPart) yet I fail to solve the problem. Regards, Balmer.

ps: I got three more questions, if you give me any hint about them I would be thankful.

1) Is there any way I can make upload only jpg, gif formats possible? No other files extensions can be allowed to be uploaded.

2) Is there any way I can make upload work only for files with e.g. 50mm x 50mm size?

3) Is there any way to add to the upload part *.tif and *.png extensions?

Former Member
0 Kudos

Hi try this code to accept only JPG files.

if (wdContext.currentContextElement().getPhotoResource().getResourceType().getFileExtension().equalsIgnoreCase("jpg")) {

wdContext.currentContextElement().setFileSize(""+ wdContext.currentContextElement().getPhotoResource().read(true).available());

} else {

IWDControllerInfo info = wdControllerAPI.getViewInfo().getViewController();

String msg = "Please upload JPG file";

IWDConfirmationDialog dialog = wdComponentAPI.getWindowManager().createConfirmationWindow( msg, info.findInEventHandlers("error"), "OK");

dialog.setTitle("File Type Eror!");

dialog.show();

}

Regards,

Shyam.

Former Member
0 Kudos

Hi, thanks for answer, I added imports and created needed methods but this two lines gave me

"Cannot invoke read(boolean) on the primitive type void" error which is hard for me to repair since my FileUpdate class is void type. Any idea? Regards

if (wdContext.currentContextElement().getPhotoResource().getResourceType().getFileExtension().equalsIgnoreCase("jpg")) {
	wdContext.currentContextElement().setFileSize(""+ wdContext.currentContextElement().getPhotoResource().read(true).available());

former_member182598
Active Contributor
0 Kudos

Hi Balmer,

Sorry for the late reply. I was away from SDN for some time. Which Version of WebDynpro You are using? If you are using NW04S there is a much cleaner and straightforward API.

Yu can refer to the links

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/00062266-3aa9-2910-d485-f1088c3a...

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/b0e10426-77ca-2910-7eb5-d7d8982c...

Hope It helps.

Regards

Prashant