New topic Closed topic
avatar image
2
Uploading an image in a HTTP POST/PUT JSON request
By Created , last editted

It is possible to upload an image through a HTTP PUT/POST JSON request. You just need to encode the image as an base64 encoded string and include it in JSON. For example:

Mind the '...', that is where the rest of the encoded string should be. Also pay attention to the format of the base64 encoded string. It should NOT be as following:
You should strip everything before (and including) the comma. In the case above, strip the text 'data:image/jpeg;base64,' from the value you send to the server.
Next, when uploading this text to BettyBlocks using a custom model or a separate input variable, use the 'base64_decode' expression to transform the image to an actual image file (as text). Example:
Then you can just update the entity and assign this 'decoded_picture' text expression to the property of type 'Image' (or 'File'?).

It is possible to upload an image through a HTTP PUT/POST JSON request. You just need to encode the image as an base64 encoded string and include it in JSON. For example:

Mind the '...', that is where the rest of the encoded string should be. Also pay attention to the format of the base64 encoded string. It should NOT be as following:
You should strip everything before (and including) the comma. In the case above, strip the text 'data:image/jpeg;base64,' from the value you send to the server.
Next, when uploading this text to BettyBlocks using a custom model or a separate input variable, use the 'base64_decode' expression to transform the image to an actual image file (as text). Example:
Then you can just update the entity and assign this 'decoded_picture' text expression to the property of type 'Image' (or 'File'?).
Answers
Sort by:

This topic is closed.