POST file - Error 1104 - "How do I set the KEY for the form-data?"

855 views
Skip to first unread message

Patrick Schindler

unread,
Jan 31, 2020, 11:33:08 AM1/31/20
to MIT App Inventor Forum
Hello,

SUBJECT:  RESTful API Interaction, posting files to a server with creds.


  I have basic authentication and communication working with the server that I want to post a file to.
  I have had good success communicating with this particular server using MIT AI2.

  I can use Postman successfully to post files, using the code generated below, so I know the server side is working.

  We just have to make AI2 look like that CURL, yes?


Question4.png




 In Postman I set this KEY explicitly in the BODY

Question2.png

General Procedure:
1)  Review API documentation
2)  Get it working in Postman
3)  Port it to MIT AI2



When that translates to MIT AI2, I do the following:


1)  I manually build Params from the base URL and whatever the RESTful API wants...  Authentication information usually.

2)  I use the AI2 built in functions to build up the Header

3)  I am trying to figure out how to set up the BODY, other than using the pre-baked function which takes a file path input.


Question3.png


I am an experienced developer but I am choppy around RESTful api.  I have done it many times, but a few years always goes by between using the skill set and much rust grows.

...

I have done significant debugging to ensure:

* Base URL is correct
* Params are correct (identical to CURL - the parse from JSON, from previous API hit, comes out as expected and intended)
* In my header I am only calling out content type, where as postaman includes something called "boundary"..  I do not know what that is and I am not including it.
* In my body, I am dependent on pre-built AI2 codes. . .  so I have not added the key word fileUpload

I did notice while building my query at Postman that I had to explicitly call out the KEY value for the file transfer. . .

Sigh...
Anyone want to give me some ideas for troubleshooting?

Sorry I had to scribble some things out.  Many protect their API with Security thru Obscurity.  Usually I criticize this form of security, but in this case, obscurity really does slow down the adversary.

thanks,
-Schindler









Patrick Schindler

unread,
Jan 31, 2020, 11:46:17 AM1/31/20
to MIT App Inventor Forum
Information on boundary from Stack Exchange
https://stackoverflow.com/questions/3508338/what-is-the-boundary-in-multipart-form-data

Apparently it is just a unique key-word used to bound the data in the file.
As in literally..
Define the key word
Write the key word
Spill the file
Write the key word

OK - so the Key Word to be used has to be defined in the Header.
Maybe AI2 is expecting this, I will add it.

... 

As for how I know (or think) my combined params are correct, I inspected it on the Error Screen.

-Schindler

Patrick Schindler

unread,
Jan 31, 2020, 11:55:34 AM1/31/20
to MIT App Inventor Forum
Test Results:

I added "boundary" header line with an arbitrary sequence of chars for value
The behavior did not change


In other news (since this is a complicated thing that can go wrong for any of 28 reasons...)

My logic that the URL in general is good and that I do not need URI encode or anything like that
1)  I added URI encode, got error for invalid URL
2)  My understanding is that the built in tools perform this conversion, even if building up a URL of all sorts of funny characters.

-Schindler

Patrick Schindler

unread,
Jan 31, 2020, 11:59:27 AM1/31/20
to MIT App Inventor Forum
Changed content-type to Content-Type
No change


I think my next step is to try and see the generated output from the AI2 blocks.

I am only testing this thru
1)  Trial and error
2)  Spill on the 1104 Error

That would be the next logical thing to do - tho - not sure quire how yet.

-Schindler

Patrick Schindler

unread,
Jan 31, 2020, 12:04:19 PM1/31/20
to MIT App Inventor Forum
Research on this forum leads to:


which leads to


which leads to the fact that I am posting to an Amazon Server and everything is set tight...  so that may be my issue.

Exploring that lead now

-Schindler

Patrick Schindler

unread,
Jan 31, 2020, 12:11:20 PM1/31/20
to MIT App Inventor Forum
Based on that research (Pura Vida of course has been very helpful in learning to work with AI2)

1)  I am going to assume (possibly false assumption) that my Server is not friendly to the way we are trying to write files to it (?!?)
(tho...  its sole purpose...  is to take in files...  and it works in PostMan...  but still thinking I have to write to the body a key word)

Assuming I am unable to solve that, here are plans B & C

A)  I can push files to one of my other servers or FTP
(but that does not web-integrate with my primary goal, which is to upload files to the "documents" section of a popular database website)
(this solution would put links in my target database website, outside links...  and that is bad news long term)

B)  I can take the "known good" HTML output from PostMan and try to manually execute in some way
(So basically inline some HTTPS)


I am running short on time now, but this must be solved.
I will solve it.

-Schindler


Patrick Schindler

unread,
Jan 31, 2020, 12:21:18 PM1/31/20
to MIT App Inventor Forum
Time is up. . .  
I am going to move forward on plan B.

FTP via https://puravidaapps.com/ftp.php

Later if we solve this, great.

My core requirement is:
"Upload Test Reports to a Web Database"

This will allow me to make a nice    
YEAR/MONTH/DAY 
folder structure along with an
HH:MM:SS.txt
File structure

Good day
-Schindler

Patrick Schindler

unread,
Jan 31, 2020, 12:59:32 PM1/31/20
to MIT App Inventor Forum
Update:
Tested the FTP Extension demo - works excellent.

Procedure:
1)  Log into your webserver              ($6/mo, so why do you not have one?  Wordpress is your friend!  I use iPage but have used many)
2)  Create an FTP Sub Account       (gives a User/Password access to a specific folder tree, dont give away root!)
3)  Enter the FTP sub account information into your FTP demo

-Create folder works
-Upload image works

Great. . .  Extremely powerful tool.
That will NO DOUBT take care of the business I need to take care of an in a much smarter way.

This forum rocks

you...  know...  how...  long...  it would have taken me to write an FTP client?
OMG...  I could do it...  but ... pfffttt...   a long time.  I really appreciate folks making Extension available.  Super happy to pay.

... and since I do not come around often
MIT AI2 is awesome.  Incredible effort.  Cant wait to see if it gets ported over to Apple.

I do not develop for Apple Devices (Android Only)
I develop close to the Hardware (NFC, BLE, Camera, etc)
If AI2 code (or some subset) ran on both Apple and Android - that would be a big win for the Kids.

thanks,
-Schindler

Chris Ward

unread,
Jan 31, 2020, 3:20:36 PM1/31/20
to MIT App Inventor Forum
Sorry Patrick - we have moved!

Reply all
Reply to author
Forward
0 new messages