Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Upload a file from WD

Hello experts,

i am trying to implement a upload Ui Element from WD.

Unfortunately I have some problems with my Action "UploadFile".

Here ist the implemented Code-Section:

onActionFileUpload (com.sap.tc................wdEvent)

{

IPrivateUploadScreen.IContextElement element = wdContext.currentContextElement();

if (element.getFileResource()!=null){

IWDResource resource = element.getFileResource();

element.setFileSize(this.getFileSize(resource))

....

.....

This WD-App is based on the "Uploading and Downloading Files in Web Dynpro Java" Tutorial.

The Problem ist that method setFileSize isn't a member of the Object element.

Any ideas?

Regards Marco

Former Member
Former Member replied

Hi,

You need to have the following function in your controller.

Following function is available in https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/00062266-3aa9-2910-d485-f1088c3a4d71

Page 11.

//@@begin others
/** Read resource and calculate file size.
* @return the file size in Bytes, KB or MB as String */
private String getFileSize(IWDResource resource) {
InputStream stream = null;
DecimalFormat myFormatter = new DecimalFormat("###.##");
double size = 0;
String unit = "";
try {
stream = resource.read(false);
size = stream.available();
if (size < 1024) {
unit = " Bytes";
unit= } else if (size < 1048576) {
size = size / 1024;
unit = " KB";
unit= } else if (size < 1073741824) {
size = size / 1024 / 1024;
unit = " MB";
} } catch (IOException e) {
wdComponentAPI.getMessageManager().reportException(
e.getLocalizedMessage(), true);
} finally {
iftream != null) {
(s try {
stream.close();
} catch (IOException e) {
wdComponentAPI.getMessageManager().reportException(//@@end

Regards

Ayyapparaj

0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question