Using a WEB PUT or POST method with Amazon Web Service S3

787 views
Skip to first unread message

Karen O'Connell

unread,
Sep 10, 2014, 5:17:15 PM9/10/14
to mitappinv...@googlegroups.com
I'm making an app that needs to GET a file from my Amazon S3 bucket, and then PUT or POST files to the same bucket. Currently, GET works fine on files I've manually uploaded to my bucket, but when I try to POST or PUT anything, I get a 400 response code for PUT and a 412 response code for POST. I've modified the bucket permissions to allow everyone read/write access, and added the POST and PUT methods to the CORS configuration for my bucket. Any ideas why I keep getting errors for POST and PUT? Thanks in advance.

Taifun

unread,
Sep 10, 2014, 5:26:38 PM9/10/14
to mitappinv...@googlegroups.com
It would really help if you provided a screenshot of your relevant blocks, so we can see what you are trying to do, and where the problem may be.
also a link to the Amazon S3 documentation could help...

Taifun

Trying to push the limits of App Inventor! Snippets and Tutorials from Pura Vida Apps by Taifun.         

Karen O'Connell

unread,
Sep 10, 2014, 5:37:08 PM9/10/14
to
My blocks attached. I get a 200 ResponseCode for the GET and a 400 ResponseCode for the Put.
putfileblock.jpg

Karen O'Connell

unread,
Sep 10, 2014, 5:38:19 PM9/10/14
to mitappinv...@googlegroups.com

Karen O'Connell

unread,
Sep 10, 2014, 5:54:47 PM9/10/14
to mitappinv...@googlegroups.com
Also a link to a log that shows up in my bucket after one of my PUT attempts.
logs.jpg

Taifun

unread,
Sep 10, 2014, 6:17:48 PM9/10/14
to mitappinv...@googlegroups.com

Taifun

unread,
Sep 10, 2014, 6:24:08 PM9/10/14
to mitappinv...@googlegroups.com
did you set web2.SaveResponse to true?
set it to false and use the Web.GotText event instead
probably you will get some responseContent which explains the error more in detail
Taifun

Karen O'Connell

unread,
Sep 10, 2014, 6:25:17 PM9/10/14
to mitappinv...@googlegroups.com
No I'm not sure, but if that's the only option then I believe it. If I make the WEB url a presigned URL as explained here, http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-query-string-auth.html , do you think App Inventor's WEB tool would understand it?

Also, are there better places than Amazon for data storage using App Inventor's PUT and POST? Thanks so much.

Taifun

unread,
Sep 10, 2014, 6:27:30 PM9/10/14
to mitappinv...@googlegroups.com
did you set web2.SaveResponse to true?
set it to false and use the Web.GotText event instead
probably you will get some responseContent which explains the error more in detail

Also, are there better places than Amazon for data storage using App Inventor's PUT and POST?
Google Drive works fine, see my interface here
Taifun

Karen O'Connell

unread,
Sep 10, 2014, 6:34:16 PM9/10/14
to mitappinv...@googlegroups.com
I tried setting SaveResponse to false and used a GotText event, which gave me the following:

responseCode = 400
responseType = XML
responseContent = <?xml version="1.0"encoding="UTF-8"?>
<Error><Code>MalformedXML</Code><Message>The XML you provided was not well-formed or did not validate against our published schema</Message><RequestId>7595A45C275E2BB8</RequestId><HostId>NB23h3+U3p3DfTNqUVoeaEvlyjhVJLA6xF733NTZTy5D2OH9FTi7rXAIc4H/qMg+iVZ4GmCQ/b8=</HostId></Error>

Taifun

unread,
Sep 11, 2014, 9:32:05 AM9/11/14
to mitappinv...@googlegroups.com
probably you have to set some headers?
see the example below
however you can't get the content length of your image automatically, which probably is a show stopper...
Taifun

The following request stores the image my-image.jpg in the bucket myBucket.

PUT /my-image.jpg HTTP/1.1
Host: myBucket.s3.amazonaws.com
Date: Wed, 12 Oct 2009 17:50:00 GMT
Authorization: authorization string
Content-Type: text/plain
Content-Length: 11434
Expect: 100-continue
[11434 bytes of object data]

mac

unread,
Sep 11, 2014, 3:00:13 PM9/11/14
to mitappinv...@googlegroups.com
Thank you so much. Do you know the best way to put that code into the WEB tool?

Taifun

unread,
Sep 11, 2014, 4:07:05 PM9/11/14
to mitappinv...@googlegroups.com
if you want to set the headers, you should use the Web.RequestHeader property

coming back to the Authentication
If I make the WEB url a presigned URL as explained here, http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-query-string-auth.html , do you think App Inventor's WEB tool would understand it?
this should work, but it is not an easy task, you have to calculate the signature and encrypt it, this example could help you doing this https://puravidaapps.com/encrypt.php

however in the end I think, you will not be able to put a file to your Amazon S3 Bucket because as already mentioned, you can't get the file length of the file to be transferred and this is a showstopper...

I recommend you to use Google Drive https://puravidaapps.com/drive.php or store your files on a web server https://puravidaapps.com/postfile.php

Taifun 
Reply all
Reply to author
Forward
0 new messages