Posts: 32
Registered: 7/18/05
Forum Points: 6
How to upload a file via ABAP RFC with Webdynpro ?
Posted: Nov 23, 2005 10:45 PM
Hi everyone,
I have the follwing problem.
I`m currently creating a webdynpro DC to upload files to a mySAP CRM system via RFC.
The RF-module is already available at the backend side and I have imported it as a model. The ABAP module interface looks like this:
*" IMPORTING
*" VALUE(IV_CASE_GUID) TYPE SCMG_CASE_GUID
*" VALUE(IV_FILENAME) TYPE SDOK_PROPV DEFAULT 'Case Document'
*" VALUE(IV_MODELNODE) TYPE STRINGVAL DEFAULT '19'
*" VALUE(IV_FILE_CONTENT_BINARY) TYPE SDOKCNTBINS OPTIONAL
*" EXPORTING
*" VALUE(EV_MESSAGE) TYPE BAPI_MSG
*" EXCEPTIONS
*" UPLOAD_FAILED
//create new list object
Sdokcntbin bin = new Sdokcntbin(); //create a temporary byte array with length of the line to be inserted into the list.
byte[] b = new byte[bin.getLine().length]; **read the inputStream into the byte array**
inputStream.read(b); ??? //write the byte array into the list
bin.setLine(b); //add list to input node for RFC
ModelNode.addIv_File_Content_Binary(bin);
Posts: 2,972
Registered: 3/3/04
Forum Points: 7,127
Re: How to upload a file via ABAP RFC with Webdynpro ?
Posted: Nov 24, 2005 10:15 AM in response to: Xiaopeng Tan
Xiaopeng,
Yes, you have to read input stream by 1022 bytes chunk, and create Sdokcntbin per chunk.
Something like this:
final int chunkSize = 1022;
final byte[] chunk = new byte[chunkSize];
final BufferedInputStream in
= new BufferedInputStream(resource.getInputStream());
try
{
int size = -1;
while ( (size = in.read(chunk, 0, chunkSize)) > 0 )
{
// If last chunk is partial, pad rest with zeros
if ( size < chunkSize )
Arrays.fill( chunk, size, chunkSize, 0); //create new list object
final Sdokcntbin bin = new Sdokcntbin();
//write the byte array into the list
bin.setLine(chunk);
//add list to input node for RFC
<ModelObject>_Input.addIv_File_Content_Binary(bin);
}
}
finally
{
in.close();
}
Message was edited by: Valery Silaev
Posts: 32
Registered: 7/18/05
Forum Points: 6
Re: How to upload a file via ABAP RFC with Webdynpro ?
Posted: Nov 24, 2005 11:51 AM in response to: Valery Silaev
Hi Valery,
That's exactly what I was looking for. It's working now. Perfect!
Thank you very much!
Best regards,
Xiaopeng