Picture management

Hello,

Can you describe briefly how you’re managing pictures storage, both on the rasp and on the server?

I want to create an interface easier for the user to manage (download and delete) old pictures. I think about something like a gallery in the photo farmware page, bellow the actual image viewer. What’s the best way to do that? (I can code and push it) This topic is an example of someone how needed this improvement.

I also want to create timelapses of growing plants, so it will be great to be able to keep those pictures separate from the others for each plant and allow an easy download for the user.

1 Like

@Pitou That’s a great question. Photos are a RESTful resource that can be managed like any other API resource. That is to say, a photo is not much different than a Point or a PinBinding. On the production server, they are stored in Google Cloud Storage. For self-hosters, the photos are stored to disk.

I’ve provided 3 examples below:

  • Retrieve all images
  • Retrieve a single image
  • Delete a single image

To run the examples below, you will need to put an auth token in your authorization header. You will also need a reliable HTTP client for whatever programming language you decide to build your image management tool with.

Retrieve All Images

Perform an HTTP GET to my.farm.bot/api/images

The response will look like this:

[
  {
    "id": 6,
    "created_at": "2019-11-07T15:01:17.999Z",
    "updated_at": "2019-11-07T15:01:17.999Z",
    "device_id": 249,
    "attachment_processed_at": null,
    "attachment_url": "https://i.imgur.com/EBhHoye.jpg",
    "meta": {
      "x": 1,
      "y": 2,
      "z": 3
    }
  }
]

Delete Image with ID of 3

Perform an HTTP DELETE request to my.farm.bot/api/images/3

The server will return an empty response.

Retrieve a single Image with ID of 4

GET /api/images/4

Perform an HTTP GET to my.farm.bot/api/images/4

The response will look like this:

{
  "id": 4,
  "created_at": "2019-11-07T15:01:17.954Z",
  "updated_at": "2019-11-07T15:01:17.954Z",
  "device_id": 248,
  "attachment_processed_at": null,
  "attachment_url": "https://i.imgur.com/EBhHoye.jpg",
  "meta": {
    "x": 1,
    "y": 2,
    "z": 3
  }
}
3 Likes

As a side note to the information above, examples on how to manage all REST resources can be found here.

Generally speaking:

  • An HTTP GET with no ID will list all resources of a particular type GET /api/sequences
  • An HTTP GET with an ID will list a single resource GET /api/points/456
  • An HTTP PUT or PATCH with an ID will change the contents of a resource. You must provide a JSON object in the request body with the updated fields. PUT /api/regimens
  • An HTTP POST without an ID will create a resource. You must provide the resource contents as JSON in the request body. POST /api/points
  • An HTTP DELETE with an ID will destroy a resource. DELETE api/sensors/1
2 Likes

Looking forward to your great ideas @Pitou! I would be definitely your first customer ;=)

Thanks @RickCarlino for your answer.
I found later this post witch is useful.
It appears that the API call to my.farm.bot/api/images only gives the 100 last pictures, it might be a problem later for what I’m planning to do.

I needed to generate images to store on my development server, but my test Raspberry Pi hasn’t a camera :confused:.
So I create the Fake-Camera Farmware :wink:

3 Likes