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’, )
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).
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…) 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.
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:
Hi. The example you provided did’t work in my case. Probably because the component (Editor.js) executes the request as
multipart/form-data I will have to figure out how to parse the incoming request first.
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/, 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.
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 )