Skip to Content
0
Jan 24, 2007 at 01:31 PM

Unable to Upload the image to the binary type context Attribute.

21 Views

Hi folks,

I am trying to Upload an image to the binary type context Attribute using the File Upload UI element. On selecting the file using the Browse button and on clicking the button Upload which calls the method onActionUpload.

what is actually happening is this

after using the browse button to select a file to be uploaded, when I press the Upload button to invoke the uploadAction event Handler , <b>the view(page) reloads</b> no corresponding messages in the code are printed and <b>the message in wdInit() gets printed again</b>

the code piece for <b>onActionUpload</b> and <b>wdinit( )</b> from the view controller are as follows

public void wdDoInit()

{

//@@begin wdDoInit()

IWDMessageManager msgMgr = wdComponentAPI.getMessageManager();

msgMgr.reportSuccess("inWdInit");

IWDAttributeInfo attributeInfo =

wdContext.getNodeInfo().getAttribute(

IPrivateFileUploadView.IContextElement.FILE_RESOURCE);

attributeInfo.getModifiableSimpleType();

wdContext.currentContextElement().setDetailsVisibility(

WDVisibility.NONE);

//@@end

}

Method for action upload

public void onActiononUpload(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

{

//@@begin onActiononUpload(ServerEvent)

IWDMessageManager msgMgr = wdComponentAPI.getMessageManager();

msgMgr.reportSuccess("onClick of Upload");

IWDAttributeInfo attributeInfo =

wdContext.getNodeInfo().getAttribute(IPrivateFileUploadView.IContextElement.FILE_RESOURCE);

IWDModifiableBinaryType binaryType = (IWDModifiableBinaryType)attributeInfo.getModifiableSimpleType();

IPrivateFileUploadView.IContextElement element = wdContext.currentContextElement();

if (element.getFileResource() != null)

{

try {

String mimeType = binaryType.getMimeType().toString();

byte[] file = element.getFileResource();

msgMgr.reportSuccess("file value"+file.toString());

//get the size of the uploaded file

element.setFileSize(this.getFileSize(file));

//get the extension of the uploaded file

element.setFileExtension(binaryType.getMimeType().getFileExtension());

element.setDetailsVisibility(WDVisibility.VISIBLE);

wdComponentAPI.getMessageManager().reportMessage(

IMessageFileUploadComp.SF__UPLOAD,

new Object[] { binaryType.getFileName()},

false);

}

catch (Exception e)

{

throw new WDRuntimeException(e);

}

}

else

{

msgMgr.reportSuccess("Nothing in the context Attribute");

element.setDetailsVisibility(WDVisibility.NONE);

msgMgr.reportContextAttributeMessage(

element,

attributeInfo,

IMessageFileUploadComp.NO__FILE,

new Object[] { "" },

true);

}

msgMgr.reportSuccess("File in Context attribute");

element.setFileResource(null);

msgMgr.reportSuccess("File thrown out of Context attribute");

//@@end

}

Kindly suggest..................guide me trace the errors if any....or the correct way to do it

Thanks

Paras