on 04-22-2013 10:03 PM
WebDynpro Experts,
I encountered a problem in Web Dynpro for ABAP. Hope you could shine some lights on it
I added a file upload and download feature in an ABAP WebDynpro application. But I have an issue when I try to download a file. It works for file type like jpg, pdf or txt, but not for MS documents like doc, docx, xls, xlsx, or ppt.
I remember the file download used to work for all file types. Maybe the new SAP support pack we lately installed broke it.
Steps for Reconstruction
1) I created a sample app based on the following tutorial.
http://wiki.sdn.sap.com/wiki/display/WDABAP/Upload+and+Download+files+in+Webdynpro+ABAP
2) Click on the Browse button to select any word or excel documents
like doc, docx, xls or xlsx from your local machine. Then click on
Upload button. You will see the uploaded file is added to the table
below.
3) Click on the file you just uploaded or any files that I have
uploaded. The doc or xls file displays in a mess. The docx or xlsx file
opens or saves in a weird zip file format (See detailed error in the
attached file.)
Any help would be greatly appreciated with awarded points.
Thanks
Joanna
I guess you forgot the attachment. Furthermore share your exact SAP release including SP levels and kernel patch level. Meanwhile double check also that you have correctly bound the mimeType to the context.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Samuli,
Thank you for your reply. I try to attach some documents (doc or jpg or png) for detail error messages but it kept giving me errors- "The content type of this attachment is not allowed"???
Anyway, the miletypes are correct.
application/vnd.openxmlformats-officedocument.wordprocessingml.document for C:\Users\joanna_shi\Desktop\warranty\test.docx
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet for C:\Users\joanna_shi\Desktop\warranty\test10.xlsx
application/msword for C:\Users\joanna_shi\Desktop\warranty\cforia- customer-child_doc.doc
application/vnd.ms-excel for C:\Users\joanna_shi\Desktop\warranty\Book1.xls
SAP_BASIS: SAPKB70212
SAP_APPL: SAPKH60509
Thanks
Joanna
Hi Joanna,
I believe u used file upload and file download UIs respectively for uploading and downloading the file.
I have also faced the same problem but if you upload the document you should be aware of how you are converting it. I have shared my code use it and if you still face problems specify it here.
DATA lo_nd_file_info TYPE REF TO if_wd_context_node.
DATA lo_el_file_info TYPE REF TO if_wd_context_element.
DATA ls_file_info TYPE wd_this->Element_file_info.
data: it_fileup type table of ZJFILEUP_SAVE,
wa_fileup type ZJFILEUP_SAVE.
* navigate from <CONTEXT> to <FILE_INFO> via lead selection
lo_nd_file_info = wd_context->get_child_node( name = wd_this->wdctx_file_info ).
* get element via lead selection
lo_el_file_info = lo_nd_file_info->get_element( ).
* get all declared attributes
lo_el_file_info->get_static_attributes(
IMPORTING
static_attributes = ls_file_info ).
data: lv_filena type DSVASDOCID,
lv_extn type DSVASDOCID.
CALL FUNCTION 'DSVAS_DOC_FILENAME_SPLIT'
EXPORTING
PF_DOCID = ls_file_info-file_name
IMPORTING
* PF_DIRECTORY =
PF_FILENAME = lv_filena
PF_EXTENSION = lv_extn.
wa_fileup-FILE_NAME = lv_filena.
wa_fileup-FILE_TYPE = ls_file_info-FILE_TYPE.
wa_fileup-FILE_SIZE = '10'.
wa_fileup-FILE_CONTENTS = ls_file_info-FILE_CONTENTS.
insert into ZJFILEUP_SAVE VALUES wa_fileup.
if sy-subrc eq 0.
*** get message managerdata lo_api_controller type ref to if_wd_controller.data lo_message_manager type ref to if_wd_message_manager.
lo_api_controller ?= wd_This->Wd_Get_Api( ).
CALL METHOD lo_api_controller->GET_MESSAGE_MANAGER
RECEIVING
MESSAGE_MANAGER = lo_message_manager
.
* report messageCALL METHOD lo_message_manager->REPORT_SUCCESS
EXPORTING
MESSAGE_TEXT = 'Data uploaded successfully'.
else.*** get message manager*data lo_api_controller1 type ref to if_wd_controller.*data lo_message_manager1 type ref to if_wd_message_manager.
lo_api_controller ?= wd_This->Wd_Get_Api( ).
CALL METHOD lo_api_controller->GET_MESSAGE_MANAGER
RECEIVING
MESSAGE_MANAGER = lo_message_manager
.
* report messageCALL METHOD lo_message_manager->REPORT_ERROR_MESSAGE
EXPORTING
MESSAGE_TEXT = 'Select a file and then upload'.
endif.
select file_name file_type FILE_SIZE FILE_CONTENTS from ZJFILEUP_SAVE into table it_fileup.
* navigate from <CONTEXT> to <FILE_INFO> via lead selection
lo_nd_file_info = wd_context->get_child_node( name = wd_this->wdctx_file_info ).
lo_nd_file_info->invalidate( ).
lo_nd_file_info->bind_table( new_items = it_fileup set_initial_elements = abap_false ).
Hope my code snippet will solve your issue.
My code snippet shows uploading data to a Ztable and to download the same use the Download UI element, i believe you are aware of file download ui and no codes has to be written for downloading.
Thanks & Regards
Arun.K.P
Hi Arun,
Thank you for your reply. I tried your coding but still have the same issue. After I upload a file (test.docx) and then click on the file name (test.docx), it gives me the Open or Save options. As you may see from the image, the file type is zip file now instead of a word doc. That's why I am having trouble either saving or opening the file. The same thing happens to xlsx, doc or xls files, only Microsoft products though. Other files like jpg or pdf or txt files are opened or saved fine.
Do you think the file content has some issues? Currently the file content is defined as XSTRING in the table and view context. Is it right?
Thanks
Joanna
Hi Joanna,
did you try saving the "~wd_key.zip" file and opening it? Try to download the file and change its name and extension to "test.docx" and then open it with "Openoffice" or "MS Word".
If that works, you just have an issue with the filename and mimetype, and not with the XSTRING you have uploaded.
Each file, regardless of which type, is up-/downloaded as a XSTRING. The XSTRING is your content. Along with the XSTRING, you have to provide the filename and mimetype, which specify the filetype and program to open with. I assume, the content will not be the issue, since it works with other files like jpg.
Check during uploading, which filename and mimetype are set, and why you get the "wd_key.zip"-name when downloading.
You should also check your whitelist. Maybe you are not allowed to up/download files of MS-Office-files. You can setup/view the whitelist with transaction WDR_ACF_WLIST. (You have to download it on your computer to have the "license" to up/download files and also to start local programs)
BR
ismail
Hi Ismail,
I tried exactly what you did about saving the "~wd_key.zip" file and opening it, and it worked.
Our basis folks are not familiar with the WDR_ACF_WLIST, but they don't think office documents would be restricted because we upload them just fiine everywhere else. We are more inclined to agree with you that there is some issue with the mine type. It seems like it is storing the type correctly, but maybe not passing it back correctly when we try to download the content. Is it really working in your system?
Thanks
Joanna
We finally found the problem- I didn't bind mineType property in the Download Table File Content Field (this is missed in the above tutoral link). After I did that, it all works well now. I also bound the fileName property in the Downlaod Table File content Field, and now the file name shows better too. Thank you all for you guys' help.
btw, why am I not able to award more points or mark this post as resolved?
Thanks
Joanna
User | Count |
---|---|
84 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.