on 07-22-2011 9:51 PM
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
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
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
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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This message was moderated.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
can you paste your code here?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.