. . .

Images and Files

We offer you to upload images to your backend. Both are up- and downloadable from a client app or the dashboard. While you use images or files, remember the space limitation that comes with your chosen plan.

via Dashboard

Upload

If you want to upload images you can use the dashboard. Just create a new Module with a class, which has an attribute of the type “image” and deploy your app. Now go to the “Data” tab, add an object of that class and click into the table cell of the image attribute. Choose the image you want to upload and confirm.

images/download/attachments/11568135/uploadImage.png

For files it’s pretty much the same.

images/download/attachments/11568135/uploadFile.png

Download

If you want to download a file or picture click on the picture icon in the dialog or on the clip.

images/download/attachments/11568135/downloadImage.png

via SDK

For info about how to deal with files and images in our SDKs, please check out our SDK Reference.

via cURL

The REST API for managing images and files is documented in the apidocs.

Upload

For uploading an image you send a HTTP POST request to the REST resource /yambas/rest/apps/{appName}/data/images. You have to replace {appName} by the name of your app and send the picture’s data in the HTTP body. Optional parameters are the name and format of the picture.

For uploading a file there’s another REST resource: /yambas/rest/apps/{appName}/data/files, which works the same way. To upload an image use this cURL command:

Bash
 curl -F "file=@MYPICTURE.JPG" -F "apiKey=MYAPIKEY" -F "system=LIVE" -F "name=myimage" https://HOSTNAME/yambas/rest/apps/MYAPPNAME/data/images

MYPICTURE.JPG stands for the location of your image while MYAPIKEY is a placeholder for the APIKey of your app which you can find in the App Setup screen of your dashboard. Also you have to replace MYAPPNAME wihin the URL with the name of your app.
If you want to upload a file just replace “images” with “files” within the URL.

This command returns the IMAGEID. You need this ID to access this image later.

Download

If you upload a file or picture you receive the IMAGEID. You need the ID and the APIKey of your app to get the picture.

Then you can download the image as json from the resource /yambas/rest/apps/{appName}/data/images/{imageId}.
Or download the image as mimetype image with appending “.img” to this resource.

Bash
curl http://HOSTNAME/yambas/rest/apps/MYAPP/data/images/IMAGEID.img?apiKey=YOURAPIKEY

You can also send the API key as header instead of a parameter with the option -H “X-apiomat-apikey:YOURAPIKEY”.
As with uploading, downloading files instead of images works the same way, just use the resource/yambas/rest/apps/{appName}/data/images/{imageId}. Here you can append “.img” as well to download the file with its correct mimetype instead of json.

If you want to access a picture you’ve uploaded with cURL with an SDK, you can load the image from the href: /yambas/rest/apps/MYAPP/data/images/IMAGEID.img?apiKey=MYAPIKEY

Again replace MYAPP with the name of your app, IMAGEID with the ID you received after uloading and MYAPIKEY with the APIKey of your app.

Image scaling and resizing

When downloading or embedding an image you can adjust some parameters in the URL to scale and resize the image, as well as setting a background color, alpha channel and transcode the image to a different format. How you do that is documented in this REST API doc section.
The parameters width and height control the scaling and resizing. When you set both of them, the image gets resized and it’s up to you to keep or change the aspect ratio of the image. When you set just one of them, the image gets scaled with the other value automatically adjusted to keep the image’s original aspect ratio. For example, when you uploaded an image with 480×320 (w x h) pixel, and you download the image with the width set to 240 pixel, the height automatically gets set to 160 pixel and the aspect ratio of 4:3 stays the same.

The corresponding cURL command looks like this:

cURL
curl "https://HOSTNAME/yambas/rest/apps/YOURAPPNAME/data/images/YOURIMAGEID.img?width=240&apiKey=YOURAPIKEY"
* link only available in Enterprise Documentation