on 2023 May 14 7:02 AM
Hi,
Issue :- Attachment not opening/downloading.
We have used sapui5 uploadset to handle upload/download attachment in our application.
<upload:UploadSet id="UploadSet1" instantUpload="false" showIcons="true" uploadEnabled="true" afterItemAdded="onAfterItemAdded" uploadCompleted="onUploadCompleted" noDataText="No File" noDataDescription="No File attached" uploadUrl="../../../../upload" items="{path: 'data>/truckFiles', templateShareable: false}">
<upload:items>
<upload:UploadSetItem fileName="{data>Filename}" mediaType="{data>MimeType}" visibleEdit="false" visibleRemove="false" url="{data>__metadata/media_src}"></upload:UploadSetItem>
</upload:items>
</upload:UploadSet>
Now, this is how data is stored image.png . When we try to open/download the attachment. It doesn't open and says It appears we don't support this file format.
get_stream code is below:-
We had to add set_header here referring https://netweaver65.rssing.com/chan-15006850/article194.html , because without that , it downloading files with the name of entity.
File open with text and shows "{"mediaType":"image/png","fileName":"image.png","size":20274}".
METHOD /iwbep/if_mgw_appl_srv_runtime~get_stream.
DATA ls_lheader TYPE ihttpnvp.
DATA : ls_media TYPE zdtt_insp_media.
DATA(lt_keys) = io_tech_request_context->get_keys( ).
DATA(lv_inspid) = VALUE #( lt_keys[ name = 'INSP_ID' ]-value OPTIONAL ).
DATA(lv_filename) = VALUE #( lt_keys[ name = 'FILENAME' ]-value OPTIONAL ).
ls_lheader-name = 'Content-Disposition'.
* ls_lheader-value = 'outline; filename="Mobile.pdf";'.
ls_lheader-value = |outline; filename={ lv_filename };|.
set_header( is_header = ls_lheader ).
IF lv_inspid IS NOT INITIAL AND lv_filename IS NOT INITIAL.
SELECT SINGLE FROM zdtt_insp_media
FIELDS insp_id, filename, cr_date,cr_time,value, mimetype
WHERE insp_id = @lv_inspid
AND filename = @lv_filename
INTO ( @ls_media-insp_id,@ls_media-filename,@ls_media-cr_date,@ls_media-cr_time,@ls_media-value, @ls_media-mimetype ).
IF sy-subrc EQ 0.
copy_data_to_ref( EXPORTING is_data = ls_media
CHANGING cr_data = er_stream ).
ENDIF.
ENDIF.
ENDMETHOD.
Thank you sergiorecasens , I will check on it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
First, check if the URL format of each element of the UploadSetItem type is correct. It must have the '$value' option to the end of the URL. For example:
/sap/opu/odata/sap/ZTEST_SRV/FileSet(ID='123456')/$value
If you don't add '$value' option, you will be calling the GET_ENTITY method (FILESET_GET_ENTITY in this example) instead of the GET_STREAM method.
Then, in the implementation of the GET_STREAM method, I recommend returning a structure of the standard type ty_s_media_resource, which is the same as the one used by default in the CREATE_STREAM method, as follows:
DATA: ...
ls_stream TYPE ty_s_media_resource.
...
set_header( is_header = ls_header ).
ls_stream-value = lv_content. " lv_content is the raw value of the file
ls_stream-mime_type = lv_mime_type.
copy_data_to_ref(
EXPORTING
is_data = ls_stream
CHANGING
cr_data = er_stream ).
Regards,
Sergio.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
john.patterson3
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
67 | |
10 | |
10 | |
10 | |
7 | |
7 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.