Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Rest response sending multiple csv files

ekekakos
Participant
0 Kudos

Hello. I need desperately your help because I have stuck. The requirement is the following:

They want to create a Rest WS that it will be called any time they want from an external application, they will pass some parameters, the WS will select the data from SAP depending on the importing parameters and it will return the ITAB in a CSV format with some other returning information data. Because the data in the majority will be more than 80000 records they want to split the results in more than 1 csv files.

Is there anyone who implement a REST WS like the above, to include in its response except some other data (message, date etc) and multiple files?

I will be much obliged if someone can help me.

Thanks

Elias

2 REPLIES 2

Sandra_Rossi
Active Contributor
0 Kudos

Well, the proposed solution is weird. You'd better do the same as OData i.e. the requestor requests the number of lines they want (e.g. top and skip "parameters"). Or they should be able to split themselves the 80000 records.

If you still want to continue with multiple files returned, you can use a multipart response with a boundary to separate the CSV files:

  • HTTP Multipart RFC7231
    • 3.1.1.4 Multipart Types -> MIME RFC2046

e.g. response body:

Content-Type: multipart/mixed;
	boundary="----_=_NextPart_001_01CAAA37.2647E86A"

This is a multi-part message in MIME format.

------_=_NextPart_001_01CAAA37.2647E86A
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

Hello,

please find attached a document

Bye

------_=_NextPart_001_01CAAA37.2647E86A
Content-Type: text/csv; name="file1.csv"
Content-Transfer-Encoding: base64
Content-Description: file1.csv

e1xydGYxXGFkZWZ...

------_=_NextPart_001_01CAAA37.2647E86A Content-Type: text/csv; name="file2.csv" Content-Transfer-Encoding: base64 Content-Description: file2.csv e1xydGYxXGFkZWZ...

Tomas_Buryanek
Active Contributor
0 Kudos

One possible solution. But always check with the WS consumer (client) if they would be able to consume WS like this.

  1. They will call WS with parameter how many lines one file can have - for example /document/123?max_allowed_lines=80000.
  2. In SAP backend you check if result file will have total_lines > max_allowed_lines.
  3. If yes then return one file with max_allowed_lines and and also return info, that this is file 1 out of X. Here are some ways how this could be returned.
  4. Then in next call they will ask for file number 2 etc. For example (not sure if this is good/correct approach with ../2/.. 😞
    /document/123/2/?max_allowed_lines=80000

Another way would be using ?offset=8000 => you send lines 8000-16000.

-- Tomas --