cancel
Showing results for 
Search instead for 
Did you mean: 

Preview Documents .docx, png using GET_STREAM OData

prince_isaac
Active Participant
0 Kudos

Hi Experts

My requirement is to preview any document attached on PO's and i have implemented GET_STREAM on the OData. I am able to preview .PDF documents however no other document types will preview. They are immediately downloaded which is not what i want.

    CALL FUNCTION 'SO_DOCUMENT_READ_API1'
      EXPORTING
        document_id                = lv_docid
      IMPORTING
        document_data              = ls_document_data
      TABLES
        contents_hex               = lt_hex_content
      EXCEPTIONS
        document_id_not_exist      = 1
        operation_no_authorization = 2
        x_error                    = 3
        OTHERS                     = 4.
    
    IF sy-subrc = 0.
      IF lt_hex_content IS NOT INITIAL.
*...set streaming
        ls_stream-mime_type = |application/| && |{ ls_document_data-obj_type }|.

        LOOP AT lt_hex_content ASSIGNING FIELD-SYMBOL(<ls_hex_content>).
          IF ls_stream-value IS INITIAL.
            ls_stream-value = <ls_hex_content>-line.
          ELSE.
            ls_stream-value = ls_stream-value && <ls_hex_content>-line.
          ENDIF.
        ENDLOOP.

        copy_data_to_ref( EXPORTING is_data = ls_stream
                          CHANGING  cr_data = er_stream ).

*...Download or Preview the document
        ls_header-name = 'content-disposition'.
        ls_header-value = 'inline; filename="' && ls_document_data-obj_descr &&
                          |.| && |{ ls_document_data-obj_type }| && |";|.   "preview
        set_header( is_header = ls_header ).

      ENDIF.
    ENDIF.

PDF documents will preview in the browser but other types will download immediately yet i want to preview in the browser.

regards

Prince Isaac

muppiris
Member
0 Kudos

Hello Prince Isaac,

Did you manage to find an answer to preview the .docx(word) file with out downloading it ?

Thanks and Regards,

Harsha.

Accepted Solutions (1)

Accepted Solutions (1)

prince_isaac
Active Participant
0 Kudos

Update:

I have managed to get some document types to preview but one in particular .DOC still downloads immediately. Changes i had to make was to retrieve the MIME_TYPE from table SDOKFEXT using the file extension of the document.

*...set media type
        ls_stream-mime_type = me->get_mime_type( |{ ls_document_data-obj_type CASE = LOWER }| ).

        LOOP AT lt_hex_content ASSIGNING FIELD-SYMBOL(<ls_hex_content>).
          IF ls_stream-value IS INITIAL.
            ls_stream-value = <ls_hex_content>-line.
          ELSE.
            ls_stream-value = ls_stream-value && <ls_hex_content>-line.
          ENDIF.
        ENDLOOP.

        copy_data_to_ref( EXPORTING is_data = ls_stream
                          CHANGING  cr_data = er_stream ).

*...Download or Preview the document
        ls_header-name = 'content-disposition'.
        ls_header-value = 'inline; filename="' && ls_document_data-obj_descr &&
                          |.| && |{ ls_document_data-obj_type }| && |";|.   "preview
        set_header( is_header = ls_header ).

Answers (0)