# Upload a base64-Picture-String via event message (thinedge) to Cumulocity

**URL:** <https://community.cumulocity.com/t/upload-a-base64-picture-string-via-event-message-thinedge-to-cumulocity/7564>\
**Category:** Forum\
**Tags:** cumulocity-edge, cumulocity\
**Created:** [November 1, 2022, 12:37pm UTC](https://community.cumulocity.com/t/upload-a-base64-picture-string-via-event-message-thinedge-to-cumulocity/7564 "2022-11-01T12:37:53Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![KevinBecker](https://avatars.discourse-cdn.com/v4/letter/k/35a633/32.png) [@KevinBecker](https://community.cumulocity.com/u/KevinBecker)\
**Post date:** [November 1, 2022, 12:37pm UTC](https://community.cumulocity.com/t/upload-a-base64-picture-string-via-event-message-thinedge-to-cumulocity/7564/1 "2022-11-01T12:37:53Z")

</div>

#### What product/components do you use and which version/fix level are you on?

latest

#### Is your question related to the free trial, or to a production (customer) instance?

production

#### What are you trying to achieve? Please describe it in detail.

I try to upload a picture to cumolocity. It is converted to a base64-String and I try to send it via an event message as a normal dictionary payload → image\_string

| 
```
1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
```
 | 
```
event_msg_dict={"time": event_time,"event\_type": event_type,"child\_type":self.MessageTopic,"text": text,"lot": HIBC_Code_Contents.LOT_Number,"ref": HIBC_Code_Contents.ProductCode,"producer": HIBC_Code_Contents.ManufacturerCode,"udi-type": udi_type,"udi-code":self.Content_String,"quality":self.ScanQuality,"test\_status":self.TestStatus,"reason":self.Reason,"image\_string":self.image_string,"location": location
}
```
 |

#### Do you get any error messages? Please provide a **full error** message screenshot and log file.

 ![grafik](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/4/a/4ac86ef87205323d4814fbe19941519526ccb667.jpeg)

The text over the error is part of the string for internal debug purposes. The Error below is ocurring, when we try to send a dictionary with this string included. If we try to send it without the string (simply commented out the entry but didnt change anything else) it will send the event-message just fine.

#### Have you installed all the latest fixes for the products and systems you are using?

yes

---

<div class="post-metadata">

**Author:** ![Murat\_Bayram](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/murat_bayram/32/3670_2.png) [@Murat\_Bayram](https://community.cumulocity.com/u/Murat_Bayram)\
**Post date:** [November 1, 2022, 1:22pm UTC](https://community.cumulocity.com/t/upload-a-base64-picture-string-via-event-message-thinedge-to-cumulocity/7564/2 "2022-11-01T13:22:55Z")

</div>

Since the issue comes from that FS\_Peripherals.py it makes sense to share that code.

Could you give some more infos why you want to do that? You could also add images via the file repository as well.

---

<div class="post-metadata">

**Author:** ![Harald\_Meyer](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/harald_meyer/32/1959_2.png) [@Harald\_Meyer](https://community.cumulocity.com/u/Harald_Meyer)\
**Post date:** [November 1, 2022, 1:41pm UTC](https://community.cumulocity.com/t/upload-a-base64-picture-string-via-event-message-thinedge-to-cumulocity/7564/3 "2022-11-01T13:41:58Z")

</div>

Specifically, the Event API supports attachments. That way the file is attached to the life cycle of the event.  
[https://cumulocity.com/api/10.14.0/#tag/Attachments](https://cumulocity.com/api/10.14.0/#tag/Attachments)

My guess is that the body of your request is too large an rejected by the HTTP server. How large is the image you are trying to attach?

---

<div class="post-metadata">

**Author:** ![KevinBecker](https://avatars.discourse-cdn.com/v4/letter/k/35a633/32.png) [@KevinBecker](https://community.cumulocity.com/u/KevinBecker)\
**Post date:** [November 2, 2022, 9:07am UTC](https://community.cumulocity.com/t/upload-a-base64-picture-string-via-event-message-thinedge-to-cumulocity/7564/4 "2022-11-02T09:07:38Z")

</div>

The Picture is aproximately 64KB, it varies a little bit depending on the actual object it is taken from.

Since we are using Thinedge to send our Data to Cumolocity, can you please specify under which MQTT-topic and with which payload we have to publish in order to upload the picture as a binary in the first place?

---

<div class="post-metadata">

**Author:** ![Harald\_Meyer](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/harald_meyer/32/1959_2.png) [@Harald\_Meyer](https://community.cumulocity.com/u/Harald_Meyer)\
**Post date:** [November 2, 2022, 9:27am UTC](https://community.cumulocity.com/t/upload-a-base64-picture-string-via-event-message-thinedge-to-cumulocity/7564/5 "2022-11-02T09:27:50Z")

</div>

Ok, I assumed you were using HTTP. The API I linked to is not available via MQTT.

For MQTT the maximum message size is 16KB, so I assume you run into that limit:  
[https://cumulocity.com/guides/device-sdk/mqtt/#overview](https://cumulocity.com/guides/device-sdk/mqtt/#overview)

---

<div class="post-metadata">

**Author:** ![KevinBecker](https://avatars.discourse-cdn.com/v4/letter/k/35a633/32.png) [@KevinBecker](https://community.cumulocity.com/u/KevinBecker)\
**Post date:** [November 2, 2022, 9:36am UTC](https://community.cumulocity.com/t/upload-a-base64-picture-string-via-event-message-thinedge-to-cumulocity/7564/6 "2022-11-02T09:36:55Z")

</div>

Ok, then how do I upload pictures with thinedge to Cumolocity?

or please suggest best practise to stream real images coming from devices.

---

<div class="post-metadata">

**Author:** ![Murat\_Bayram](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/murat_bayram/32/3670_2.png) [@Murat\_Bayram](https://community.cumulocity.com/u/Murat_Bayram)\
**Post date:** [November 2, 2022, 10:11am UTC](https://community.cumulocity.com/t/upload-a-base64-picture-string-via-event-message-thinedge-to-cumulocity/7564/7 "2022-11-02T10:11:16Z")

</div>

Could you please tell us a bit about the use case.

Images can not be uploaded via mqtt directly but via Rest. There is currently an feature request open for that:

> <https://github.com/thin-edge/thin-edge.io/issues/1315>
>
> \*\*Is your feature improvement request related to a problem? Please describe.\*\*
> …The configuration/log plugin has implemented a logic to upload files to the binary storage of Cumulocity,
> However if I develop an own plugin and need to upload files to the binary storage of c8y, I currently can not do so without implementing own Rest API logic into my plugin, using the jet token etc. .
> 
> \*\*Describe the solution you'd like\*\*
> Since file upload logic is already available somehow in the code I would basically wish something on the cli such as:
> 
> \`\`\`bash
> tedge file upload c8y --file /test/filename.txt
> \`\`\`
> 
> For the cli I used the structure of the cert upload. I would basically expect to get back the binaryID of the uploaded file.

However you could handle the RestCall in your own plugin and attach it to an event. @Harald_Meyer referenced the API call already for that.

---

<div class="post-metadata">

**Author:** ![Harshil\_Gandhi](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/harshil_gandhi/32/6222_2.png) [@Harshil\_Gandhi](https://community.cumulocity.com/u/Harshil_Gandhi)\
**Post date:** [November 2, 2022, 10:43am UTC](https://community.cumulocity.com/t/upload-a-base64-picture-string-via-event-message-thinedge-to-cumulocity/7564/8 "2022-11-02T10:43:18Z")

</div>

Is it possible through Device Integration using Smart Rest Templates?

---

<div class="post-metadata">

**Author:** ![Harshil\_Gandhi](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/harshil_gandhi/32/6222_2.png) [@Harshil\_Gandhi](https://community.cumulocity.com/u/Harshil_Gandhi)\
**Post date:** [November 3, 2022, 12:34pm UTC](https://community.cumulocity.com/t/upload-a-base64-picture-string-via-event-message-thinedge-to-cumulocity/7564/9 "2022-11-03T12:34:42Z")

</div>

We have now published image through thin edge topic and can be retrieved through events (UTF-8 Encoding)

Use case was simple, we need end to end streaming for our images through thin edge.  
Still there is no component which supports decoding of image real time on UI

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/system/32/31990_2.png) [@system](https://community.cumulocity.com/u/system)\
**Post date:** [May 2, 2023, 12:35pm UTC](https://community.cumulocity.com/t/upload-a-base64-picture-string-via-event-message-thinedge-to-cumulocity/7564/10 "2023-05-02T12:35:35Z")

</div>

Closed on May 2, 2023, 12:35pm UTC

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