on 05-18-2020 4:17 PM
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
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 ).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
89 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.