# Image from stream

**URL:** <https://community.homey.app/t/image-from-stream/138616>\
**Category:** Developers\
**Tags:** app\
**Created:** [June 23, 2025, 6:30pm UTC](https://community.homey.app/t/image-from-stream/138616 "2025-06-23T18:30:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![OlaSt](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/olast/32/17168_2.png) [@OlaSt](https://community.homey.app/u/OlaSt)\
**Post date:** [June 23, 2025, 6:30pm UTC](https://community.homey.app/t/image-from-stream/138616/1 "2025-06-23T18:30:42Z")

</div>

I am trying to fetch an image and use it as an CameraImage. But there is (as always) a great lack of samples. This does not make an image, and I guess it is because I dont understand this magic.

I need to do it this way, ordinary url files when using chrome on a desktop (works fine on phone)

Anyone able to make a short sample?

```auto
async onInit() {
	myImage.setStream(async (stream) => {
	    const res = await this.homey.fetch("https://IMGURL");
	    if (!res.ok) {
		throw new Error("Invalid Response");
	    }

	    return res.body.pipe(stream);
	});
	this.setCameraImage('blabla', "this is my testimage", myImage);
}

```

---

<div class="post-metadata">

**Author:** ![RonnyW](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ronnyw/32/10879_2.png) [@RonnyW](https://community.homey.app/u/RonnyW)\
**Post date:** [June 24, 2025, 4:20pm UTC](https://community.homey.app/t/image-from-stream/138616/2 "2025-06-24T16:20:50Z")

</div>

Please check the type of `res.body` if it’s a streaming object. I use `res.pipe.stream` instead, but I don’t use fetch(). Perhaps the body is already converted to string/json.

Example:

> <https://github.com/RonnyWinkler/homey.blink/blob/a634a46377b27e85c9468c09bb5853b7558bf0bd/drivers/camera/device.js#L90>

I use standard https module to save some kB memory for additional NPM modules 😄.

> <https://github.com/RonnyWinkler/homey.blink/blob/a634a46377b27e85c9468c09bb5853b7558bf0bd/lib/blinkApi.js#L551>

PS: the handler registered in `setStream` is called every time the image is requestes. This is done in device camera/image view but also when the image token is used in AdvancedFlow (e.g. sending the image as push message).

---

<div class="post-metadata">

**Author:** ![OlaSt](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/olast/32/17168_2.png) [@OlaSt](https://community.homey.app/u/OlaSt)\
**Post date:** [June 24, 2025, 6:55pm UTC](https://community.homey.app/t/image-from-stream/138616/3 "2025-06-24T18:55:50Z")

</div>

Great, this was the sample I needed to go further. Thanks!

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [June 25, 2025, 5:02am UTC](https://community.homey.app/t/image-from-stream/138616/4 "2025-06-25T05:02:20Z")

</div>

> [@RonnyW](#):
>
> Please check the type of `res.body` if it’s a streaming object

If it wasn’t, `res.body.pipe()` would throw an error.
