cancel
Showing results for 
Search instead for 
Did you mean: 

0 bytes resource

Former Member
0 Kudos

Hi there,

I'm trying to use FileUpload component with no sucess. No matter what I do I always get a 0-byte long resource (all other resource attributes are ok, such as resource name, mime type, and so forth). The resource.read(false) method always return an empty InputStream. Should I do something with the resource before it is populated with real bytes???

Best,

Ricardo

Accepted Solutions (1)

Accepted Solutions (1)

lokesh_kamana
Active Contributor
0 Kudos

Hi,

Below is the code snipplet which is working.Please try and let me know.

Here Va_Resource is an attribute of type "com.sap.ide.webdynpro.uielementdefinitions.Resource" binded to the FileUpload UI Element.


int fileLength = 0;
String fileStrData = null;
try {
	// Writing file content to a String variable in Byte format
	byte fileData[] = null;
	// Read the file from the Resource attribute into an input stream
	InputStream fileIs = wdContext.currentContextElement().getVa_Resource().read(false);
	// creating Byte array stream
	ByteArrayOutputStream bOut = new ByteArrayOutputStream();
	// Declaring length variable
	int length;
	byte[] part = new byte[10 * 1024];
	// Writing file content
	while ((length = fileIs.read(part)) != -1) 
	{
	bOut.write(part, 0, length);
	}
	// Closing the file
	fileIs.close();
	// Converting to byte array
	fileData = bOut.toByteArray();
	fileLength = fileData.length;
	bOut.close();
} catch (Exception e) {
	wdComponentAPI.getMessageManager().reportException("Exception"+e.getLocalizedMessage());
}

Print the variable filelength and let me know you are getting any value in it or not.

Thanks & Regards,

Lokesh Kamana.

Former Member
0 Kudos

Hi,

Unfortunately neither alternatives presented here worked for me. I'm sure the problem is not with this code snippet but with some other configuration wrongly done.

I have exported an SCA with two very simple DCs, in case someone here could gently try to reproduce the problem and suggest a fix. Please find it at http://uploading.com/files/bfbdb4mb/BPMCMIS00_0.sca/ (you have to click on download and wait 60 seconds)

First DC - bpm-cmis-gui - contains a component called UploadFileComponent with a single view. In this view there is a method called onActionUploadFileCompletedEvent() with the logic suggested on this thread. The other DC is a client of this (reusable) component and contains only one Application. This is the one you should run in order to check that nothing is read from the uploaded file.

PS.: I'm using NW CE 7.2.

Any help would be appreciated.

Best regards,

Ricardo Giacomin

lokesh_kamana
Active Contributor
0 Kudos

Hi,

I am not able to import ur SCA file into NWDS.

So can you please paste the code which ever ur using to upload.

The code which i have pasted is the custom development which i have done in CE 7.2 and its working fine.

Ru using any ready made component.

If so please try just creating a simple webdynpro application and test my code.

Before that please copy your code here so that i can help you.

Thanks & Regards,

Lokesh Kamana

Former Member
0 Kudos

Lokesh,

The code I'm using is exactly the one you suggested. That's why I think the problem is not with the code but with the configuration.

Any idea about why you were not able to import the SCA (any meaningful message?)?

Regards,

Ricardo Giacomin

lokesh_kamana
Active Contributor
0 Kudos

Hi,

Firstly the process what i know in importing an SCA file is checking in through NWDI to the track.

But i dont have any NWDI setup.

So if you know any other process please suggest me i have the SCA file with me.

We have developed a custom webdynpro DC in which this code is working.

So i dont understand what is the configuration you are talking about.

Thanks & Regards,

Lokesh Kamana

Former Member
0 Kudos

Lokesh,

In order to import the SCA into NWDS, please open the Development Infrastructure perspective, right-click on Local Development (in the Component Browser view) and choose Import SC. After that, select both DCs and choose Sync/Create Project from the context menu.

As for your question, when I say the problem is not on the code but on the configuration, I mean the error is not on the onActionUploadFileCompletedEvent() method, which I implemented using the logic you suggested, but in other configuration stuff like the way I defined/configured the Context structure, etc.

Best,

Ricardo Giacomin

lokesh_kamana
Active Contributor
0 Kudos

Hi,

I imported the SCA files and deployed the DC and it works fine for me.


	  	IPrivateUploadFileView.IContextElement element = wdContext.currentContextElement();
		IWDResource resource = element.getFile();

		byte fileData[] = null;

		// if a file in the FileUpload field exists
		if (resource != null) {
			try {

				int fileLength = 0;

				InputStream fileIs = resource.read(false);
				ByteArrayOutputStream bOut = new ByteArrayOutputStream();

				int length;
				byte[] part = new byte[10 * 1024];
				while ((length = fileIs.read(part)) != -1) {
					bOut.write(part, 0, length);
				}

				fileIs.close();
				fileData = bOut.toByteArray();
				fileLength = fileData.length;
				bOut.close();
				wdComponentAPI.getMessageManager().reportSuccess("File Length"+fileLength);
				if (fileData == null || fileLength == 0) {
					throw new RuntimeException("File data is null or zero-byte");
				}

			} catch (Exception e) {
				wdComponentAPI.getMessageManager().reportException(e);
			}
		} else {
			wdComponentAPI.getMessageManager().reportException("File not defined");
		}
	  
	    wdThis.wdGetUploadFileComponentController().fireUploadFileCompletedEvent();

wdComponentAPI.getMessageManager().reportSuccess("File Length"+fileLength);

Is printing the size

Note:-1.There is no issue in ur component possible reason might be try uploading different files.

2.Try reinstalling your NWDS and import the SCA then which could fix this issue.

Thanks & Regards,

Lokesh Kamana.

junwu
Active Contributor
0 Kudos

i deployed your dc,

try to upload a file, no error, nothing is printed.

Former Member
0 Kudos

Lokesh and John,

Thank you very much for your help. Indeed, there was no problem with the code or whatsoever. I had to restart the JEE server and everything suddenly worked!

Best regards,

Ricardo Giacomin

Answers (3)

Answers (3)

Former Member
0 Kudos

Read the [tutorial|http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/9076a593-2b08-2d10-2890-9a7078246ec4] in the [WD Java Demo Kit|http://wiki.sdn.sap.com/wiki/display/WDJava/WebDynproforJavaDemo+Kit], this should answer your question.

Former Member
0 Kudos

This message was moderated.

junwu
Active Contributor
0 Kudos

can you paste your code here?