# Using Lua to take a photo and editing the meta data

**URL:** <https://forum.farmbot.org/t/using-lua-to-take-a-photo-and-editing-the-meta-data/9235>\
**Category:** Software Development\
**Created:** [July 17, 2024, 1:59pm UTC](https://forum.farmbot.org/t/using-lua-to-take-a-photo-and-editing-the-meta-data/9235 "2024-07-17T13:59:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![aeroptl](https://forum.farmbot.org/letter_avatar_proxy/v4/letter/a/958977/32.png) [@aeroptl](https://forum.farmbot.org/u/aeroptl)\
**Post date:** [July 17, 2024, 1:59pm UTC](https://forum.farmbot.org/t/using-lua-to-take-a-photo-and-editing-the-meta-data/9235/1 "2024-07-17T13:59:22Z")

</div>

Hello,

I’m looking to use Lua code to take a photo (which is already shown in the documentation). But this time, I need to edit the meta data associated with it. Looking at the MQTT broker, the image metadata is usually x,y,z and name, but I need to add in a tag so I can extract the image separately. I’m aware I’ll have to make a HTTP Post request but I’m not sure how it would work in Lua.

Has anyone managed to do something like this before?

Thanks.  
P

---

<div class="post-metadata">

**Author:** ![jsimmonds](https://forum.farmbot.org/user_avatar/forum.farmbot.org/jsimmonds/32/1470_2.png) [@jsimmonds](https://forum.farmbot.org/u/jsimmonds)\
**Post date:** [July 18, 2024, 12:27pm UTC](https://forum.farmbot.org/t/using-lua-to-take-a-photo-and-editing-the-meta-data/9235/2 "2024-07-18T12:27:41Z")

</div>

Hi @aeroptl

> [@aeroptl](#):
>
> I’m aware I’ll have to make a HTTP Post request but I’m not sure how it would work in Lua.

The HTTP method (request) for this is **put**

There’s a recent discussion about **meta** property updates here →   
[Iterating over variables to associate plants with soil moisture readings - Software / Sequences - FarmBot Forum](https://forum.farmbot.org/t/iterating-over-variables-to-associate-plants-with-soil-moisture-readings/9205)

---

<div class="post-metadata">

**Author:** ![aeroptl](https://forum.farmbot.org/letter_avatar_proxy/v4/letter/a/958977/32.png) [@aeroptl](https://forum.farmbot.org/u/aeroptl)\
**Post date:** [July 22, 2024, 8:25am UTC](https://forum.farmbot.org/t/using-lua-to-take-a-photo-and-editing-the-meta-data/9235/3 "2024-07-22T08:25:54Z")

</div>

Hello,

I tried this but it doesn’t work.

This is what I have in Lua:

```auto
result = api({
    method = "put",
    -- Don't forget the leading "/":
    url = "/api/images/",
    -- `body` is optional for GET requests.
    body = {
        meta = {
            test = "test"
        }
    }
})

```

The result is a HTTP error status 404. The developer documentation description of this call says it should create a new image.

---

<div class="post-metadata">

**Author:** ![jsimmonds](https://forum.farmbot.org/user_avatar/forum.farmbot.org/jsimmonds/32/1470_2.png) [@jsimmonds](https://forum.farmbot.org/u/jsimmonds)\
**Post date:** [July 23, 2024, 3:58am UTC](https://forum.farmbot.org/t/using-lua-to-take-a-photo-and-editing-the-meta-data/9235/4 "2024-07-23T03:58:03Z")

</div>

Hi @aeroptl

> [@aeroptl](#):
>
> I’m looking to use Lua code to take a photo (which is already shown in the documentation). But this time, I need to edit the meta data associated with it.

I assumed that you were going to capture and store an image using Lua **take\_photo()** and _ **then** _ add the **meta** key-value pair for that image in a _separate_ additional **api()** call.

To make that Lua code (above) work for an **existing image** you need to append the image **id** to your **url**.  
e.g.

```Lua
image_id = 473386
url = "/api/images/" .. tostring(image_id),

```

---

<div class="post-metadata">

**Author:** ![aeroptl](https://forum.farmbot.org/letter_avatar_proxy/v4/letter/a/958977/32.png) [@aeroptl](https://forum.farmbot.org/u/aeroptl)\
**Post date:** [July 23, 2024, 8:41am UTC](https://forum.farmbot.org/t/using-lua-to-take-a-photo-and-editing-the-meta-data/9235/5 "2024-07-23T08:41:43Z")

</div>

Sorry for the confusion.

The only problem I forsee is that take\_photo() does not give you the image\_id, thus it would be difficult for me to add the meta key-value pair for that image.

My ideal situation is that using the MQTT broker (listening to the logs), I should see the attachment URL link along with the meta data with the information I wanted to put in one message.

---

<div class="post-metadata">

**Author:** ![jsimmonds](https://forum.farmbot.org/user_avatar/forum.farmbot.org/jsimmonds/32/1470_2.png) [@jsimmonds](https://forum.farmbot.org/u/jsimmonds)\
**Post date:** [July 25, 2024, 6:00am UTC](https://forum.farmbot.org/t/using-lua-to-take-a-photo-and-editing-the-meta-data/9235/6 "2024-07-25T06:00:34Z")

</div>

@aeroptl a couple of ways to go 🙂

- Use **api()** to GET all images filtered by whichever attribute(s) make sense and then call **api()** to **put** new meta using **id** s in the filtered set and then possibly add **send\_message()** to make sure the stuff you need is in a Log record.

- The FBOS image uploader code creates the standard **meta** contents. If you are happy to build custom FBOS you could edit [farmbot\_os/lib/ext/api/image\_uploader.ex at staging · FarmBot/farmbot\_os · GitHub](https://github.com/FarmBot/farmbot_os/blob/staging/lib/ext/api/image_uploader.ex#L54) ?

---

<div class="post-metadata">

**Author:** ![system](https://forum.farmbot.org/user_avatar/forum.farmbot.org/system/32/4564_2.png) [@system](https://forum.farmbot.org/u/system)\
**Post date:** [August 24, 2024, 6:00am UTC](https://forum.farmbot.org/t/using-lua-to-take-a-photo-and-editing-the-meta-data/9235/7 "2024-08-24T06:00:41Z")

</div>

Closed on August 24, 2024, 6:00am UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
