cancel
Showing results for 
Search instead for 
Did you mean: 

File Download : Reading data from URL

Amey-Mogare
Contributor
0 Kudos

Hi,

I have a scenario where I need to read file data from a URL and provide user with Open/Save as/cancel type of pop up box.

How do I achieve it?

Thanks and regards,

Amey

Accepted Solutions (1)

Accepted Solutions (1)

ChrisPaine
Active Contributor
0 Kudos

Hi Amey,

Why not just serve the URL directly to the user - via a link UI element? They can then choose to download/save it to local file.

the following code - extracted from method GET_WWW_OBJECT of class CL_UWS_FORM_PDF_API will return an XString of a given URL. (I think this will work from WD ABAP but I am not sure!)

you could then pass this XString to the file download UI element.

DATA:
   lo_http_client TYPE REF TO IF_HTTP_CLIENT.

DATA:
   lv_str TYPE XSTRING,
   lv_i TYPE I.

   CALL METHOD cl_http_client=>create_by_url
      EXPORTING
         url          = iv_url
      IMPORTING
         client        = lo_http_client
      EXCEPTIONS
         argument_not_found = 1
         plugin_not_active = 2
         internal_error = 3.

   CHECK sy-subrc = 0.

   lo_http_client->propertytype_logon_popup = lo_http_client->co_disabled.

   lo_http_client->request->set_header_field( EXPORTING name  = '~request_method'
                                                        value = 'GET' ).

   lo_http_client->request->set_header_field( EXPORTING name  = '~server_protocol'
                                                        value = 'HTTP/1.1' ).


   CALL METHOD lo_http_client->send
      EXCEPTIONS
         http_communication_failure = 1
         http_invalid_state         = 2.

   CHECK sy-subrc = 0.

   CALL METHOD lo_http_client->receive
      EXCEPTIONS
         http_communication_failure = 1
         http_invalid_state         = 2
         http_processing_failed     = 3.

   CHECK sy-subrc = 0.

   lo_http_client->response->get_status( IMPORTING code = lv_i ).

   CHECK lv_i = 200.

   lv_str = lo_http_client->response->get_data( ).

   rv_content = lv_str.

There is probably a better way of doing this - others may know.

Amey-Mogare
Contributor
0 Kudos

Hi Chris,

Yes, you are correct about use of LinkToUrl UI element. But with use of LinkToUrl UI element, it exposes the file URL to user (it appears at bottom of browser window) and requirement mandates that I should not expose actual file url to user.

Thanks and regards,

Amey

ChrisPaine
Active Contributor
0 Kudos

Hi Amey,

what a wonderful requirement!

well the code I provided should allow you to get the Xstring from the URL - so you'll be doing pretty much exactly the same as you did in your WD Java app.

Chris

Amey-Mogare
Contributor
0 Kudos

Thanks Chris!

Answers (1)

Answers (1)

Former Member
0 Kudos

Can you pass the URL file data through WD application parameters?

If so, then you can get it by using application parameter read. Check this [Thread|http://wiki.sdn.sap.com/wiki/display/WDABAP/HowtoreadURLparametersinWebDynprofor+ABAP] for how to get URL parameters.

Amey-Mogare
Contributor
0 Kudos

Hi Sanket,

I am not sure whether I conveyed my requirement correctly.

Let me try again.

There will be a Table UI element with three columns --> File Name (String), File URL (string) and Download (Button).

Now on click of "Download" button in table row, I need to open a "Open / Save As/ Cancel" type of pop up box for downloading selected file.

I have done it in WD JAVA where it reads file byte stream from File URL and stores it into a buffer and offers it for download.

I have found this code to open file download pop-up:-


    DATA: L_CONTENT TYPE XSTRING .

      CL_WD_RUNTIME_SERVICES=>ATTACH_FILE_TO_RESPONSE(
        I_FILENAME      = P_FILENAME
        I_CONTENT       = L_CONTENT
        I_MIME_TYPE     = ''
        I_IN_NEW_WINDOW = ABAP_FALSE
        I_INPLACE       = ABAP_FALSE ) .

But I dont know how do I get XSTRING from File URL.

Thanks and regards,

Amey