Android Question Looking for example code for an AWS S3 GET

doncx

Active Member
Licensed User
Longtime User
I've been using JackKirk's *awesome* code for creating AWS S3 V4 signatures, and have been successfully uploading (PUTting) files to AWS on Android and iOS.

Now I'm working on GET code to download a binary file to an Android device.

Has anybody done this? Do you have some sample code I could view? This would help me to sort through the exact requirements.

Thanks for any assistance!
 

Ralph Parkhurst

Member
Licensed User
Longtime User
I use this and it works very well - it originally came from an example on this forum, probably also from JackKirk:


B4X:
Sub Process_Globals
    Private AWS_job As HttpJob
End Sub

Public Sub GetFromAWS(filename As String)
    Private My_AWS_S3 As AWS_S3
    My_AWS_S3.Initialize
    My_AWS_S3.AWS_URI_Is_Path_Style = False
    My_AWS_S3.AWS_Region = "ap-xxxxxxxxxxx-x"
    My_AWS_S3.AWS_End_Point = "s3-ap-xxxxxxxxxxx.amazonaws.com"
    My_AWS_S3.AWS_S3_Bucket_Name = "xxxxxx.xxxxxx"
    My_AWS_S3.AWS_S3_File_Name = filename
    My_AWS_S3.AWS_S3_HttpMethod = "GET"
    My_AWS_S3.AWS_S3_Query_map.Clear
    Private null_bytes() As Byte
    My_AWS_S3.AWS_S3_Payload = null_bytes
    My_AWS_S3.AWS_S3_OtherHeader_map.Clear
    Log(">>>" & My_AWS_S3.URI)
  
    'Set up httpjob
    AWS_job.Initialize("AWS_job", Main)
    AWS_job.Download(My_AWS_S3.URI)
  
    'Retrieve full header map
    Private wk_hdr_map As Map
    wk_hdr_map.Initialize
    wk_hdr_map = My_AWS_S3.FullHeaderMap
    Private wrk_ptr As Int

    'For each key, value pair of full header map...
    For wrk_ptr = 0 To wk_hdr_map.Size - 1
        'If not host header...
        If wk_hdr_map.GetKeyAt(wrk_ptr) <> "host" Then
            'Add it to httpjob
            AWS_job.GetRequest.SetHeader(wk_hdr_map.GetKeyAt(wrk_ptr), wk_hdr_map.GetValueAt(wrk_ptr))
            Log(">>>" & wk_hdr_map.GetKeyAt(wrk_ptr) & ", " & wk_hdr_map.GetValueAt(wrk_ptr))
        End If
    Next
    Log(My_AWS_S3.Authorization)
  
    'Add Authorization header to httpjob
    AWS_job.GetRequest.SetHeader("Authorization", My_AWS_S3.Authorization)
End Sub
 
Upvote 0
Top