How to consume rest api with input as file / binary data

How to consume rest api with input as file / binary data

  

hi.. any body know how to consume rest api with input as file image?

thank you

Hi Meri,

That totally depends on the type of REST API. Does it use multipart/form-data? Or does it expect a base64-encoded binary in a JSON attribute?

Meri meri wrote:

hi.. any body know how to consume rest api with input as file image?

thank you

Hi Meri,

I found one document for how to consume rest api (input as file image) in outsystems. Please refer below link

https://success.outsystems.com/Documentation/10/Reference/OutSystems_APIs/outsystems.api.preloader_API#Example

Hope this will helps.

Thanks,

AV


Amit Verma wrote:

Meri meri wrote:

hi.. any body know how to consume rest api with input as file image?

thank you

Hi Meri,

I found one document for how to consume rest api (input as file image) in outsystems. Please refer below link

https://success.outsystems.com/Documentation/10/Reference/OutSystems_APIs/outsystems.api.preloader_API#Example

Hope this will helps.

Thanks,

AV


hi Amit Verma,

i already try this.

but  i get this




can you help me to fix this?

Kilian Hekhuis wrote:

Hi Meri,

That totally depends on the type of REST API. Does it use multipart/form-data? Or does it expect a base64-encoded binary in a JSON attribute?

hi, killan

it use  multipart/form-data..

please help me.. T.T

405 error can show when HTTP Method mismatch. Did you set the REST API Method > HTTP Method to POST?

Hi Meri,

I recently wrote an article about how to consume multipart/form-data REST services. Please read it and if you have any questions left I'd be happy to help.

Kilian Hekhuis wrote:

Hi Meri,

I recently wrote an article about how to consume multipart/form-data REST services. Please read it and if you have any questions left I'd be happy to help.


Hi Killan,


Thank you for your answer. :)


but, do you have sample to use multipart/form-data plugin with consume Rest API?

i'm sorry, i'm beginner..

Solution

Hi Meri,

I don't have any samples unfortunately. Note that in the article I mentioned above there should be enough pointers for you to get started, see especially the "Implementation details":

  • declare the REST API Method having a Parameter with Data Type “Binary Data”, and its “Send In” Property set to “Body”;
  • you then need to add [a Content-Type tag] (via a Parameter with “Send In” set to “Header”) [see below];
  • you need the Binary Concat Forge Component, as well as Actions from the BinaryData Extension (which is a System Component, so already installed).

Then I mention my forge component:

"Regardless of the specific solution that makes sense for your project, I created a Forge Component, aptly name Multipart/form-data, that consists of a single eSpace with a number of Public Actions that aid in creating the right content:

  • MultipartFormDataCreate?—?the main Action, creates a text body consisting of the specified parts, in a multipart/form-data compatible format.
  • ContentTypeGet?—?returns the value to be used for the Content-Type header of the REST message based on the boundary used.
  • PartAdd?—?a helper Function that can be used to easily create a List of parts."

So what you need to to do is create a list of parts (using PartAdd or just ListAppend), feed it to MultipartFormDataCreate, use its output parameter BoundaryUsed as input to ContentTypeGet, and use MultipartformatDataCreate.MessageBinary as input to the Binary Parameter of your consumed REST Service, and ContentTypeGet.ContentType as input to the content type Input Parameter (or use it as a Function directly).

Solution

Kilian Hekhuis wrote:

Hi Meri,

I don't have any samples unfortunately. Note that in the article I mentioned above there should be enough pointers for you to get started, see especially the "Implementation details":

  • declare the REST API Method having a Parameter with Data Type “Binary Data”, and its “Send In” Property set to “Body”;
  • you then need to add [a Content-Type tag] (via a Parameter with “Send In” set to “Header”) [see below];
  • you need the Binary Concat Forge Component, as well as Actions from the BinaryData Extension (which is a System Component, so already installed).

Then I mention my forge component:

"Regardless of the specific solution that makes sense for your project, I created a Forge Component, aptly name Multipart/form-data, that consists of a single eSpace with a number of Public Actions that aid in creating the right content:

  • MultipartFormDataCreate?—?the main Action, creates a text body consisting of the specified parts, in a multipart/form-data compatible format.
  • ContentTypeGet?—?returns the value to be used for the Content-Type header of the REST message based on the boundary used.
  • PartAdd?—?a helper Function that can be used to easily create a List of parts."

So what you need to to do is create a list of parts (using PartAdd or just ListAppend), feed it to MultipartFormDataCreate, use its output parameter BoundaryUsed as input to ContentTypeGet, and use MultipartformatDataCreate.MessageBinary as input to the Binary Parameter of your consumed REST Service, and ContentTypeGet.ContentType as input to the content type Input Parameter (or use it as a Function directly).


Hi Killan,

i have a error

"Failed to load resource: the server responded with a status of 404 (Not Found)"


can u please check my .oap? am i wrong use Multipart/form-data?


thank youu very much

Hi Meri,

A "404" just means that the URL you specified for the REST service is not valid or otherwise not reachable. It has nothing to do with the actual implementation.

Kilian Hekhuis wrote:

Hi Meri,

A "404" just means that the URL you specified for the REST service is not valid or otherwise not reachable. It has nothing to do with the actual implementation.


Hi Killan,


hmm.. I see

thank you very much,killan.



Kilian Hekhuis wrote:

Hi Meri,

A "404" just means that the URL you specified for the REST service is not valid or otherwise not reachable. It has nothing to do with the actual implementation.


Hi Killan,

I have read your link and tried the plugin you are kindly provided. But somehow I encounter another issue.
I have put the parameters as you have instructed as below:


also, the debug value before I send the REST API is as follow:

But I have this following error message saying that the REST API provider didn't receive the binary content I sent ("missing_argument: image"):

can you please show me which one I did wrong?
I tried to understand your instruction as best as I could, but there's a possibly that I put the wrong parameter at the wrong place because English is not my first language.  
Thank you for being very helpful and understanding, Kilian.




Hi Meri,

One error I can spot is that the "ContentType" of PartAdd for the respective files should be set to the content type of that file, so e.g. "image/jpeg" for a JPG, etc. Not sure if that's where the problem orginates, but I don't think having multiple "multipart/form-data"s in one message is allowed.

This post is very helpful and is what i'm been searching for.

any update on your progress ? 

Hi,


The reply from Kilian explains step by step how to do it. And the images on meri reply should give you an idea how to use it.

But it's hard to help more without knowing the details of the services that you are trying to call.


On the images posted by meri the content types used are probably all wrong, since a multipart request should not have other parts with multipart content types.

The documentation for the service should say what the expected types should be.


Regards,
João Rosado