Uploading container data via Data API not working for me

Hi, I’m new to fmsoup (as of a couple days ago), so if this in the wrong place I apologize.

I am also new to Integrations and the Data API. I’m trying to use Javascript to be able to select an image and send it to my database using an HTTP Request. However, the image itself doesn’t load, only an icon and the image name does.

This image shows my HTML and javascript to select the file:
Picture%20picker

And this is how I am sending it with the Data API:

I tried this using Postman, and got the results I wanted, but this way does not work.

What am I doing wrong? (And I’m sure there is a much better way to format and send the request, so I’m open to that too.) Thanks!

2 Likes

Hello and welcome Patty!
I can’t be of help on your current issue but I am certain some will chime in soon to help.

Hi @PattyB,
what is the FMPA version? How do you store container data? Does the image show when you drop it manually?

The POST in your code does not have the field repetition number (i.e. /TestPicture/1). Not sure if this is mandatory but you may give it a try.

Hello @PattyB

I have not ever worked on anything involving an HTTP request to insert binary data via the Data API.

That said:

Short answer:

I'd suggest checking out:

It looks like, among other things, it will handle all the details of what you are trying to do.

End Short Answer / Begin further rambling regarding the code snippet you posted:

A quick glance suggests to me that it is going to more effort than need be.

Rather than constructing the precise format of the HTTP request, I believe it should be possible to rely upon either XMLHttpRequest, or the newer Fetch API to take care of such details.

Some examples to illustrate, courtesy of a couple of google searches:

XMLHttpRequest:

Fetch:

https://shiya.io/using-fetch-to-upload-a-file/

https://javascript.info/fetch

Taking a look at the code being used in the above examples, you can see how simple it can get.

But: The elaboration immediately above is perhaps just academic -- Great to know and learn about, but in your case, I'd suggest checking out the link in the short answer above. It looks like exactly what you could use.

HTH & kind regards,

-steve

4 Likes

Both FMPA and FMS are 18. I’ve tried storing internally, externally secure, and externally open with the same results.

Yes, the image does appear when dropping it in. I forgot to mention in the original post that I tried uploading the same picture with Postman, and it worked as I desired. (I’ll edit the original post).

I have tried it with the repetition number to no avail as well.

Does your project require you use JavaScript and the DataAPI? What you’re trying to do is pretty easy with a micro-service and a bit of (industry-standard) JDBC code. FMI has a free JDBC driver and a so-so manual that shows how to use it. I’ve done lots of JDBC, some of it with Filemaker so I’d be glad to help if you want to give that a spin. Tons of examples online.

The DataAPI forces you into FMS and a recent version of FMS. FMS meters your usage. Those restrictions are show-stoppers for me when better (non-proprietary, non-metered, industry-standard) approaches exist.

HTH

Not necessarily. What I’m ultimately trying to do is make it easy to take and insert pictures using WebDirect, similarly to the Insert From Device script step. The only way I could come up with quickly was to use javascript in a web viewer coupled with the Data API. I am definitely open to any other possible ways to accomplish this. Regarding JDBC, unfortunately, I know less about that than I do about the Data API.

The good news is that JDBC is a standard, not a proprietary technology. And, no metering on software you already “own”.

With my approach, it doesn’t matter if you’re using Web Direct, regular FileMaker, or some other application entirely (HTML Form, other program, …). The micro-service approach does not depend on FileMaker nor does it know anything about FileMaker. That’s a good (independent) thing.

The only requirement is that you can issue HTTP verbs (like POST – even from an HTML form), and send your binary data using 64-bit encoded streams like the FMP function lets you do.

Given an existing micro-service (you can set one up in about 2 minutes), this is a 30-minute job for the basic requirement.

The beauty of a micro-service is that it is easy to create, it works anywhere, it works with any operating system, it works on any computer, it works at any location, and it works with virtually unlimited users. All for free . A micro-service is NOT a plug-in, so … FileMaker or no FileMaker…a micro-service is totally independent so you can use it with any HTTP-enabled application (an application that can issue HTTP verbs like GET, POST, etc. Terminal, Browser? No problem.). What’s not to love?! You Write and Control The Code *! (not some third party).

HTH


“Weeks of coding can save you hours of planning.”
- Unknown

I should also mention that JDBC is terribly named. It really should be something like Programmable SQL. If you can do SQL, you can do JDBC.

Think for a minute about how ExecuteSQL() SHOULD work…

  1. You issue a query (ExecuteSQL(), unlike JDBC, limited to only Select).

  2. You get back a “FoundSet” in FileMaker so you can do whatever.

Unfortunately, 2. above isn’t how ExecuteSQL() works. Baffling. Instead, you just get back simple text data to do … something with.


Enter JDBC.

With JDBC, you enter your SQL and you do IN FACT get back a “FoundSet”, but it’s called a ResultSet (same idea). You can loop through the ResultSet hundreds of times faster than FMP’s slow looping.

With JDBC, you also can do, INSERT, DELETE, and UPDATE statements.

With JDBC, you can also do DDR statements like CREATE TABLE or ALTER TABLE.

With JDBC, you can also use database transactions. FileMaker’s transaction support seems limited, but it’s there.

Best yet, perhaps, if/when you move your database from FMP to another vendor (MySQL, SQL Server, etc.), your JDBC code will still work. Just change the connection string and any FMP-specific SQL syntax and you’re good to go with the new database – assuming the same schema, of course.

JDBC doesn’t force you into the Data API and FMS; JDBC works with plain old FMP.

Note that frameworks “abstract” JDBC so you don’t even need to worry about SQL at all. You just issue “save()” or “update()” method calls and the framework takes care of everything for you.

Just wanted to add a bit more detail.

HTH.


“Adding manpower to a late software project makes it later.”
- Fred Brooks (Brooks’ law)

2 Likes

So true, and it's the same for hardware projects !

3 Likes

Too many cooks spoil the plate :woman_cook:

2 Likes