Skip to Content
0
May 18, 2020 at 03:17 PM

Preview Documents .docx, png using GET_STREAM OData

565 Views

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