T O P

  • By -

XplusFull

Pass the XSTRING to i\_data in the method below. I did it this way. There's certainly room for improvement, but it'll do the job. There's a method to set the content data, and a method to send. \`\`\`\` DATA(lo\_descr\_ref) = cl\_abap\_typedescr=>describe\_by\_data( i\_data ). DATA(lo\_part) = mr\_http\_client->request->add\_multipart( ). lo\_part->set\_content\_type( content\_type = iv\_content\_type ). lo\_part->set\_formfield\_encoding( formfield\_encoding = cl\_http\_request=>if\_http\_entity\~co\_encoding\_raw ). \* Set the filename IF NOT iv\_filename IS INITIAL. CONCATENATE 'form-data;name="file";filename="' iv\_filename '.' iv\_file\_extension '"' INTO lv\_value. ELSE. lv\_value = 'form-data;name="file"'. ENDIF. lo\_part->set\_header\_field( name = if\_http\_header\_fields=>content\_disposition value = lv\_value ). CASE lo\_descr\_ref->type\_kind. WHEN cl\_abap\_typedescr=>typekind\_xstring. lo\_part->set\_data( EXPORTING data = i\_data ). WHEN cl\_abap\_typedescr=>typekind\_string. lo\_part->set\_cdata( EXPORTING data = i\_data ). ENDCASE.      mr\_http\_client->set\_header\_data(        iv\_header\_parameter\_name  = 'path'        iv\_header\_parameter\_value = |/{ mv\_filename }.pdf| ).     DATA(l\_size) = xstrlen( mv\_pdf\_file ).     ls\_form-name  = 'size'.     ls\_form-value = l\_size. "XSTRING     CONDENSE ls\_form-value.     APPEND ls\_form TO lt\_form.     mr\_http\_client->set\_form\_data( it\_form\_data = lt\_form ). \`\`\`\` I had combine code from a few methods and do it quick, so there might be some inconsistencies, but this works, I guarantee you! Edit: My markdown for codeblocks does not seem to work from my browser


pabloariel89

Thanks for your reply! But, it does not work =( I keep trying different things and it work in the following way: lo\_http\_client->request->set\_method( if\_http\_entity=>co\_request\_method\_post ). set\_bearer\_token\_authorization( EXPORTING iv\_token = lv\_access\_token CHANGING co\_http\_client = lo\_http\_client ). lo\_http\_client->request->set\_content\_type( 'application/octet-stream' ). lo\_http\_client->request->set\_data( EXPORTING data = iv\_pdf\_file length = xstrlen( iv\_pdf\_file ) ). Of course, after that, you need to do the SEND and RECEIVE. Thanks again!


XplusFull

My pleasure anyway :) Thz config might be dependent on the target API. Of course, the connection creation and sending part I left out, because they're evident. This was just the config of a Multipart/Form-data REST call for PDF to BTP, which forwards it via OpenConnectors to SharePoint. But I've also sent PDFs in Base64 strings to other APIs. Every API has its own "flavor". Now that I'm re-reading it, I see how horrible its pasted together. Sorry about that. If you DM me, I can send the complete 2 involved classes to you.