Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
wshirley
Level 8

Uploading file to AWS S3 Bucket

I'm trying to upload a text file to an Amazon AWS S3 Bucket from a Roku SDK channel.  I believe I have successfully written the code to generate the authorization signature (response now comes back as "true" instead of a "400" range error code from AWS).

I'm using the following code (with identifying info replaced with placeholder text):

  m.myUrlTransferObject = CreateObject("roUrlTransfer")
  m.urlport = createobject("roMessagePort")
  m.myUrlTransferObject.setmessageport("m.urlport")
  m.myUrlTransferObject.SetCertificatesFile("common:/certs/ca-bundle.crt")
  m.myUrlTransferObject.InitClientCertificates()
  m.myUrlTransferObject.SetRequest("Put")
  m.myUrlTransferObject.AddHeader("Put", "tmp:/MyTextFile.txt HTTP 1.1")
  m.myUrlTransferObject.AddHeader("Host","myawsbucketname.s3.amazonaws.com")
  m.myUrlTransferObject.AddHeader("Date", m.DateString)
  m.myUrlTransferObject.AddHeader("Authorization", AuthorizationHeaderString)
  m.myUrlTransferObject.AddHeader("Content-Type","text/html")
  m.myUrlTransferObject.AddHeader("Content-Length",m.TmpStrLen.tostr())
  m.myUrlTransferObject.AddHeader("Expect","100-continue")
  m.myUrlTransferObject.AddHeader("x-amz-acl","public-read")
  m.myUrlTransferObject.AddHeader("x-amz-content-sha256", Content_sha256)
  m.myUrlTransferObject.AddHeader("x-amz-date",StrippedDate)
  m.myUrlTransferObject.AddHeader("x-amz-meta-author","Xxxxxxxxxxx")
  m.myUrlTransferObject.AddHeader("X-Roku-Reserved-Dev-Id", "")
  m.myUrlTransferObject.SetUrl("https://myawsbucketname.s3.amazonaws.com")
  m.myUrlTransferObject.SetUserAndPassword("myAWSUserName","myAWSPassword")
  m.myUrlTransferObject.RetainBodyOnError(true)
  Response = m.myUrlTransferObject.AsyncPostFromString("tmp:/myTextFile.txt")
  Reason = m.myUrlTransferObject.GetFailureReason()
  Msg = m.myUrlTransferObject.GetMessagePort()
  ? "Msg = ";Msg
  ? "Response = ";
  ? Response;" "
  ? Reason 
  ? "m.myUrlTransferObject.GetFailureReason() = ";
  ? m.myUrlTransferObject.GetFailureReason()


Response comes back as true
GetFailureReason is blank
Msg is invalid

No file transfer is taking place, at least it's not showing up in the AWS S3 Bucket.

I need guidance on:

1.  The Headers and PostFromString functions.  Have constructed these correctly?  
2.  Is the Content-Type correct?
3.  Is there a way to get a more verbose response from AWS on what's happening via a Response message?

Does anyone see anything obviously wrong in how I'm approaching this?  Perhaps I'm missing a step?

Any help would be greatly appreciated.
0 Kudos