I'm trying to upload a file to Amazon S3 and haven't been able to get it to work. I've tried several different things such as an aws library on this forum that didn't work for me. (BTW - I would be willing to pay money for someone to wrap the official AWS SDK ).
Essentially I have a server where i request and receive a pre-signed url to s3. All I have to do is do a PUT on the file to s3 with the url and it should work. In fact, If I paste that url into vb.net version of a simple upload routine it works fine. If I try it with B4A i get a Forbidden-403 response. I'm curious if anyone else here has had ANY success uploading files to S3 as I use this functionality all of the time.
Here's a copy of the vb.net code to upload based on a pre-signed url I received and then a copy of the b4a code with the same url.
vb.net version
Here's a portion of my b4a code with the same url
I looked at the packets going through and the file is PUT to s3 and the headers seem to be alright but i get the Forbidden response. The code in .net works fine with the url so I can only assume it's something in my b4a code or how I'm doing it. I don't know what else to do. I've tried using the httputils2 library also and no success. Please help! Thx.
Essentially I have a server where i request and receive a pre-signed url to s3. All I have to do is do a PUT on the file to s3 with the url and it should work. In fact, If I paste that url into vb.net version of a simple upload routine it works fine. If I try it with B4A i get a Forbidden-403 response. I'm curious if anyone else here has had ANY success uploading files to S3 as I use this functionality all of the time.
Here's a copy of the vb.net code to upload based on a pre-signed url I received and then a copy of the b4a code with the same url.
vb.net version
B4X:
Sub PostToS3()
'use a presigned url
Dim filePath As String = "C:\temp\Agreement.pdf"
Dim url As String = "*** PUT REAL URL HERE ***"
Dim request As HttpWebRequest = CType(WebRequest.Create(url), HttpWebRequest)
Try
request.Method = "PUT"
Using fileStream As FileStream = File.OpenRead(filePath)
Using requestStream As Stream = request.GetRequestStream()
Dim bufferSize As Integer = 1024
Dim buffer(bufferSize - 1) As Byte
Dim byteCount As Integer = 0
byteCount = fileStream.Read(buffer, 0, bufferSize)
Do While byteCount > 0
requestStream.Write(buffer, 0, byteCount)
byteCount = fileStream.Read(buffer, 0, bufferSize)
Loop
End Using
End Using
Dim result As String
Using response As WebResponse = request.GetResponse()
Using reader As New StreamReader(response.GetResponseStream())
result = reader.ReadToEnd()
End Using
End Using
End
Catch ex As Exception
End Try
End Sub
Here's a portion of my b4a code with the same url
B4X:
Sub Process_Globals
Dim hClient As HttpClient
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
hClient.Initialize("PutTest")
End If
DoTest
End Sub
Sub DoTest()
Dim req As HttpRequest
Dim MyArray() As Byte
MyArray = ReadFile(File.DirRootExternal,"Application.pdf")
req.InitializePut2("*** same url here ***", MyArray)
req.SetContentType("application/pdf") 'Ive done it with and without this
hClient.Execute(req,1)
End Sub
I looked at the packets going through and the file is PUT to s3 and the headers seem to be alright but i get the Forbidden response. The code in .net works fine with the url so I can only assume it's something in my b4a code or how I'm doing it. I don't know what else to do. I've tried using the httputils2 library also and no success. Please help! Thx.