cancel
Showing results for 
Search instead for 
Did you mean: 

binary to "Resource" type

Former Member
0 Kudos

Hi, do you know how can I change a file from type binary to com.sap.something.Resource? Thanks in advance, Balmer

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi ,

To convert binary to PDF,

Insert a UI of type IFrame and Create value Attribute called PdfUrl.

Bind PdfUrl to IFrames source.

byte[] pdfContent = wdContext.currentOutput<Element>.getBin_File();

IWDCachedWebResource pdfResource = WDWebResource.getWebResource(pdfContent,WDWebResourceType.PDF);

try

{

wdContext.currentContextElement().setPdfUrl(pdfResource.getURL());

}

catch(Exception e)

{

wdComponentAPI.getMessageManager().reportException(e.getMessage(),true);

}

Regards,

Sunitha Hari.

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi

Use the following



byte[] data = //Your byte data

IWDResource resource = WDResourceFactory.createInputStream(data)

Regards

Ayyapparaj

Former Member
0 Kudos

Hi, it does not work, I get "Type mismatch: cannot convert from IWDInputStream to IWDResource" error. How can I change it? Regards, Blamer

Former Member
0 Kudos

Hi,

But why are using IWDInputStream in between. You can directly IWDResource from the byte content as:


byte[] byteArr = // your content.
IWDResource cache = WDResourceFactory.createCachedResource(byteArr,fileName,WDWebResourceType.JPG_IMAGE);

thanks & regards,

Manoj

Edited by: Manoj Kumar on Apr 3, 2008 4:34 PM

Former Member
0 Kudos

Ok, thanks for help. Could you please advice why this code dont project my picture?


ResultSet rs = stmt.getResultSet();
			while (rs.next()){				
			byte[] b=rs.getBytes(1);
		//IPrivateMyProjectView.IContextElement imageEle=wdContext.createContextElement();
			
		IWDResource cache = WDResourceFactory.createCachedResource(b,"photo",WDWebResourceType.JPG_IMAGE);
				
				if (cache != null) {				
					setImage2(cache.getUrl(WDFileDownloadBehaviour.OPEN_INPLACE.ordinal()));
				}		 
			}
		}
		catch(Exception e){
		wdComponentAPI.getMessageManager().reportWarning(e.toString());
	}   

Image2 - context of the Child Image, type String. Regards, Balmer.

Former Member
0 Kudos

Hi,

What is setImage2 here?

Are you sure that you are getting data from the ResultSet?

And you have mapped the source property od your image UI with setImage2?

Else it is perfectly fine.

thanks & regards,

Manoj

Former Member
0 Kudos

"What is setImage2 here?"

Image2 - Image Child, setImage2 -method. I was able to project picture this way from upload file. This below works fine


IMyProjectView.IContextElement element1 = wdContext.currentContextElement();	
					if (element1.getFileResource1() != null) 
					{
						Object IMessageMyProject = null;	
					IWDResource resource1 = element1.getFileResource1();
		if (element1.getFileResource1() != null) {
			element1.setImage1(element1.getFileResource1().getUrl(WDFileDownloadBehaviour.OPEN_INPLACE.ordinal()));
		 }	

I did equivalent thing like with element1 here but it didnt help

"Are you sure that you are getting data from the ResultSet?"

yes

"And you have mapped the source property od your image UI with setImage2?"

since I made it working in upload I think yes

Thanks for help and looking for a reply, Balmer.

Former Member
0 Kudos

To get the URL of the resource, you can just use toString().


IWDResource image = WDResourceFactory.createCachedResource(b,"photo",WDWebResourceType.JPG_IMAGE);
String url = image.toString();

See https://help.sap.com/javadocs/NW04S/current/wd/com/sap/tc/webdynpro/services/sal/datatransport/api/I...

Armin