Please plan your SCN wiki tasks accordingly.
Link to Content's target Space :
Uploading documents as attachments using cl_crm_documents class and displaying images in web ui screen.
This wiki explains how to upload documents & images using cl_crm_documents class and display images in web ui screen. The standard attachments tab lists the uploaded documents & images as individual links and the images are opened in a new window. This wiki also covers how to populate images in the standard web ui screen.
Create a component in transaction BSP_WD_CMPWB and add a view with view type 'Form View' or 'Empty View'. In this wiki its just an empty view without any context nodes.
The view layout is enhanced with a fileupload tag to upload images and an image tag to display images.
The upload event triggers the server event EH_ONUPLOAD in controller class.
The method gets triggered when user selects the file path and clicks Upload button.
The importing parameter htmlb_event_ex has reference to thtmlb:fileUpload tag. Assign htmlb_event_ex to reference variable lr_file of type ref to cl_htmlb_fileupload.
Extract filename and file extension from file path using function module 'CRM_KW_SPLIT_FILENAME'
Assign business object so that the file can be accessed from the specified business object location. Since the business object type is USER and instance identifier is sy-uname, the uploaded document can be accessed via transaction crm_kw.
The entire file content is stored as an xstring in lr_file->file_content. Since we use method create_with_table of cl_crm_documents class, the content is split into 1022 characters and inserted into an internal table.
Now, is the final step. Upload the document to the system using CREATE_WITH_TABLE method from class CL_CRM_DOCUMENTS.The method returns the logical and physical id's of the document location.
Now, the image is uploaded to the system. But in order to display the image we need to get the document location as a URL. It can be done by passing the logical and physical id's of the document to method GET_WITH_URL of class CL_CRM_DOCUMENTS.
The URL is assigned to public static variable gv_url.
In the layout the image location is passed through this variable <%= controller->gv_url. %>.