You can send an image to an API from your Dropsource app. Your image can come from inside the app, or elsewhere on the user device, such as the camera or gallery. In order to receive the image, your API can be set up to receive either base 64 encoded image strings, or file types via multipart form data.
- Add an Image Element to a page in your app. You can set the Image Asset in Properties by uploading an image manually into your project, or if you want to let the user upload their own image, use either the Take a Photo / Pick an Image Action on Android, or the Select Image from Photos Action on iOS (it allows you to select from the camera or photo library).
- To send the image as a Base 64 encoded string, your app will need to encode the image and store it in a variable to send with the API request. In Page Variables on the right of the editor, create a new variable, with a name of your choice and Swift/Java
- Add an Action to encode the image when it’s ready (make sure it’s before you use the Run API Request Action to execute the request). Use the Base64 Encode Image Action, selecting the Image (e.g. from the Element it’s displayed in).
- Add the API request that receives the image. In the Parameters, find the field that expects the image string. If you’re sending it as a Base 64 encoded string, bind the field to the Page Variable you created.
If you’re sending the image as a file type via multipart form data, you can bind the field directly to the Image Element on the Canvas.
When your request runs, it will send the image as a parameter. For a complete example of sending images to an API, check out the Photo Saver example app. You can also display images from API responses, including arrays.