cancel
Showing results for 
Search instead for 
Did you mean: 

Display image taken from Cordova in Gateway Client

Former Member
0 Kudos

I have the base64 image taken from Cordova camera plugin inside my CREATE_STREAM method. How can I save this to a Z table and display in the Gateway Client through the GET_STREAM method? What conversions are necessary to render as an image again in the Gateway Client?

Points will be awarded for helpful answers!

Thanks,

-Alex

Accepted Solutions (1)

Accepted Solutions (1)

b_punith
Participant
0 Kudos

Hi Alex,

Following are steps to handle base_64

1. You have is_media_resource-value which is "xstring" in create_stream method.

2. You need to decode the base_64 value as shown in below code.

DATA:

    lo_conv_x2c    TYPE REF TO cl_abap_conv_in_ce,

   lv_xstring     TYPE xstring,

    base64_string  TYPE string,

    base64_xstring TYPE xstring.

      lv_xstring  = is_media_resource-value.

       lo_conv_x2c = cl_abap_conv_in_ce=>create( ).

       lo_conv_x2c->convert( EXPORTING input = lv_xstring

                             IMPORTING data  = base64_string ).


*--- decoding base_64

CALL FUNCTION 'SSFC_BASE64_DECODE'

     EXPORTING

       b64data                  = BASE64_STRING

*     B64LENG                  =

*     B_CHECK                  =

     IMPORTING

       bindata                  = base64_xstring

     EXCEPTIONS

       ssf_krn_error            = 1

       ssf_krn_noop             = 2

       ssf_krn_nomemory         = 3

       ssf_krn_opinv            = 4

       ssf_krn_input_data_error = 5

       ssf_krn_invalid_par      = 6

       ssf_krn_invalid_parlen   = 7

       OTHERS                   = 8.

3. base64_xstring is your final xstring which you store in DMS and get the same using GET_STREAM with media value requet form Gateway Client.

Regards,

Punith

Former Member
0 Kudos

Hi Punith,

Thank you for your response. I have tried several things similar to what you mentioned above but keep getting the same result. I changed my code to exactly what you suggest in case I missed something but still not working. We also do not have DMS setup. Is the storage for this somehow different than if I were to just store the 'base64_xstring' value in a Z table?

Here is what I get when calling the GET_STREAM method re-render my image:

As you can see, I get a success 200 response but the image does not render. What format does the Gateway Client want/expect here!?!?

-Alex

b_punith
Participant
0 Kudos

Alex,

Following are few steps for your reference:

1. Parse base_64 value and post as shown below (not-"data:image/...):

2. As you want, create z table with xstring field:

3. When you get xstring in CREATE_STREAM, follow to convert as said in previous step and get base64_xstring.

4. Insert/Modify your z table with this xstring value.

Now, you again want to retrive the same in GET_STREAM

1. You can set mime Type  as: ls_stream-mime_type = 'image/png'

2. query to get your xstring and pass to ls_stream-value

copy_data_to_ref( EXPORTING is_data = ls_stream

                     CHANGING  cr_data = er_stream ).

Hope this should retrieve you Image back in Gateway Client.

Regards,

Punith

Former Member
0 Kudos

Punith,

Thank you very much for your response. I'm still a little frustrated how much time I spent on this when I already had the correct string conversion stored in my Z table. It ended up being the mime type that threw it off. I just accepted the default 'image/jpeg' that came through in the  is_media_resource-mime_type field. I tried switching this in the GET_STREAM method to 'image/png' as you mentioned above and I got this response in the Gateway Client:

When I click the button 'Response in Browser', I can see my image!

I'm going to accept your reply as the correct answer but still hoping you might have an idea why png is needed rather than jpeg? The content type at the frontend also shows it should be jpeg.

I can see this being an issue later on as I'm wanting to store this image in GOS but pretty sure the only file format accepted is jpeg. Let me know if you have thoughts on this.

Thanks again,

-Alex

Answers (0)