# How do I post files/images to a service in appfarm?

**URL:** <https://community.appfarm.io/t/how-do-i-post-files-images-to-a-service-in-appfarm/283>\
**Category:** Ask the community\
**Tags:** service\
**Created:** [February 21, 2023, 11:54am UTC](https://community.appfarm.io/t/how-do-i-post-files-images-to-a-service-in-appfarm/283 "2023-02-21T11:54:02Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![lbj](https://dub1.discourse-cdn.com/flex013/user_avatar/community.appfarm.io/lbj/32/82_2.png) [@lbj](https://community.appfarm.io/u/lbj)\
**Post date:** [February 21, 2023, 11:54am UTC](https://community.appfarm.io/t/how-do-i-post-files-images-to-a-service-in-appfarm/283/1 "2023-02-21T11:54:03Z")

</div>

I’m struggling setting up a service in Appfarm that accepts an image or file as input to a service endpoint. One of my coded components can automatically POST to a service when user drops/copy paste or upload an image. I would like to store that image in the datastore and send back the URL to the component. Are there any examples for how to set up such a service? (eg ‘Content-Type’: ‘image/png’, )

---

<div class="post-metadata">

**Author:** ![kristian](https://dub1.discourse-cdn.com/flex013/user_avatar/community.appfarm.io/kristian/32/58_2.png) [@kristian](https://community.appfarm.io/u/kristian)\
**Post date:** [February 22, 2023, 9:49am UTC](https://community.appfarm.io/t/how-do-i-post-files-images-to-a-service-in-appfarm/283/2 "2023-02-22T09:49:00Z")

</div>

Hi! We do have an example service for sending PDF files as “base 64” strings to Appfarm. See “Services” section in Showroom. However, it has not been documented in docs yet for the PDF case, since it seems we do have some charset issues with PDFs coming in as base64 strings. However, you could try this approach with image/png!

If sending files as base64 strings to Service Endpoints with POST is not the way to go, let us now. There are other ways to post images/files as well, such as doing a POST with “multipart/form-data” but we have not investigated this yet (not any known cases created in Appfarm with this yet).

---

<div class="post-metadata">

**Author:** ![lbj](https://dub1.discourse-cdn.com/flex013/user_avatar/community.appfarm.io/lbj/32/82_2.png) [@lbj](https://community.appfarm.io/u/lbj)\
**Post date:** [February 22, 2023, 10:50am UTC](https://community.appfarm.io/t/how-do-i-post-files-images-to-a-service-in-appfarm/283/3 "2023-02-22T10:50:02Z")

</div>

Thanks! I’ll have a look at the example. As for the return value; the URL to the image at appfarm, I guess I need to store a lookup value to another service …/getImage/:imageId rather than the fileContent url ([https://storage.googleapis.com](https://storage.googleapis.com)…) of the image that is returned when the image is sucessfully uploaded? The fileContent url is not a permalink is it? By “store” I mean embedding the image URL in the document produced by the coded component.

---

<div class="post-metadata">

**Author:** ![kristian](https://dub1.discourse-cdn.com/flex013/user_avatar/community.appfarm.io/kristian/32/58_2.png) [@kristian](https://community.appfarm.io/u/kristian)\
**Post date:** [February 22, 2023, 11:25am UTC](https://community.appfarm.io/t/how-do-i-post-files-images-to-a-service-in-appfarm/283/4 "2023-02-22T11:25:34Z")

</div>

Hi! The filecontent URL is permanent, however, if it should be accessible from “outside” Appfarm, the “Create File Object” must have the “Public” flag set:  
 ![image](https://europe1.discourse-cdn.com/flex013/uploads/appfarm/original/1X/f1fcb925a53b9aac263458a7e7ea9b3d5fa30d1b.png)

---

<div class="post-metadata">

**Author:** ![lbj](https://dub1.discourse-cdn.com/flex013/user_avatar/community.appfarm.io/lbj/32/82_2.png) [@lbj](https://community.appfarm.io/u/lbj)\
**Post date:** [February 24, 2023, 9:21am UTC](https://community.appfarm.io/t/how-do-i-post-files-images-to-a-service-in-appfarm/283/5 "2023-02-24T09:21:06Z")

</div>

Hi. The example you provided did’t work in my case. Probably because the component (Editor.js) executes the request as [`multipart/form-data`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST) I will have to figure out how to parse the incoming request first.

---

<div class="post-metadata">

**Author:** ![kristian](https://dub1.discourse-cdn.com/flex013/user_avatar/community.appfarm.io/kristian/32/58_2.png) [@kristian](https://community.appfarm.io/u/kristian)\
**Post date:** [February 24, 2023, 11:50am UTC](https://community.appfarm.io/t/how-do-i-post-files-images-to-a-service-in-appfarm/283/6 "2023-02-24T11:50:58Z")

</div>

If sending in “multipart/form data” to our endpoint, that body is accessible! It’s just converted to JSON. If you try posting that file to e.g. [https://webhook.site/](https://webhook.site/), you may have a look at how that body looks, or you may try mapping the whole body to a string in the service endpoint, and log it to console to see how it looks. Once you know the structure, it should be easier.

It might be that we are missing something here, but my hypothesis is that is should be possible.

---

<div class="post-metadata">

**Author:** ![lbj](https://dub1.discourse-cdn.com/flex013/user_avatar/community.appfarm.io/lbj/32/82_2.png) [@lbj](https://community.appfarm.io/u/lbj)\
**Post date:** [February 28, 2023, 9:55am UTC](https://community.appfarm.io/t/how-do-i-post-files-images-to-a-service-in-appfarm/283/7 "2023-02-28T09:55:18Z")

</div>

I could not get this working in a service, but I understand Appfarm will have better support for binary data in the future. The solution for my particular problem was solved, passing the data directly from the coded component to Appfarm (see # [How do I send a file object from a coded component to the datastore](https://community.appfarm.io/t/how-do-i-send-a-file-object-from-a-coded-component-to-the-datastore/295) )

---

<div class="post-metadata">

**Author:** ![jeremy.jean](https://dub1.discourse-cdn.com/flex013/user_avatar/community.appfarm.io/jeremy.jean/32/123_2.png) [@jeremy.jean](https://community.appfarm.io/u/jeremy.jean)\
**Post date:** [November 20, 2024, 1:29pm UTC](https://community.appfarm.io/t/how-do-i-post-files-images-to-a-service-in-appfarm/283/8 "2024-11-20T13:29:21Z")

</div>

Hello @kristian, any update here on how to push files to AF services ?  
I tried to use the example you provided in showroom, but none of the mimeType I tried are working (pdf/png/jpeg). Files are correctly created, but not usable at all.

---

<div class="post-metadata">

**Author:** ![kristian](https://dub1.discourse-cdn.com/flex013/user_avatar/community.appfarm.io/kristian/32/58_2.png) [@kristian](https://community.appfarm.io/u/kristian)\
**Post date:** [November 29, 2024, 10:35am UTC](https://community.appfarm.io/t/how-do-i-post-files-images-to-a-service-in-appfarm/283/9 "2024-11-29T10:35:22Z")

</div>

Hi!

It should be working now, with the following approach (example):

1. The Service Endpoint: Use a body parser, and then map the rawBodyData to a service variable:  

2. The Action executed by the Service Endpoint: Use a Create File Object with the following settings (note the encoding here…):  

I believe the request towards the service endpoint (1) should have `Content-Type: text/plain; charset=latin1`. Here’s an example setup of an Web Request sending a file to a Service Endpoint.

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/appfarm/original/2X/4/435fbeb6179ccb4de9c7f3bfca4af7ec9a586dbc.png)

---

<div class="post-metadata">

**Author:** ![jeremy.jean](https://dub1.discourse-cdn.com/flex013/user_avatar/community.appfarm.io/jeremy.jean/32/123_2.png) [@jeremy.jean](https://community.appfarm.io/u/jeremy.jean)\
**Post date:** [December 1, 2024, 7:30am UTC](https://community.appfarm.io/t/how-do-i-post-files-images-to-a-service-in-appfarm/283/10 "2024-12-01T07:30:35Z")

</div>

Hi Kristian,  
Thanks for the answer, but on my side, I don’t see any _Custom File Content Encoding_ option in the create file object node, is this something that will be available in the next release ?

---

<div class="post-metadata">

**Author:** ![kristian](https://dub1.discourse-cdn.com/flex013/user_avatar/community.appfarm.io/kristian/32/58_2.png) [@kristian](https://community.appfarm.io/u/kristian)\
**Post date:** [December 2, 2024, 7:57am UTC](https://community.appfarm.io/t/how-do-i-post-files-images-to-a-service-in-appfarm/283/11 "2024-12-02T07:57:28Z")

</div>

Ah, yes, new feature under feature flag.

DM me the solution name and I’ll enable!
