Uploading to Amazon S3

I am trying to use the new S3 plugin for MBS to upload files to Amazon, I can get it to upload pictures, but for some reason, I can’t upload files, can someone please take a look and tell me what I am doing wrong:

I am compiling this for windows in case that makes any difference.

[code]dim d as UploadCURL
dim f as FolderItem = FileList.RowTag(0)
if FolderExists(f) then
dim e as integer
dim bs as BinaryStream = BinaryStream.Open(f)

d = new UploadCURL
d.stream = bs
d.OptionInFileSize = bs.Length
d.OptionUpload = True
d.OptionVerbose = True
d.CollectDebugData = True

dim AWSAccessKeyId as String = “<>”
dim AWSSecretAccessKey as String = “<>”
dim Region as String = “us-west-2”
dim BucketName as string = “<>”
dim d2 as new Date
dim FileName as string = d2.SortableString + “_” + f.DisplayName 'Sortable string is a routine that I use to make a date and time stamp that sorts correctly in Windows
dim Service as String = “s3”
dim Path as String = “/” + BucketName + “/” + Filename
dim Domain as String // empty for auto
dim Verb as String = “PUT”
dim HashedPayload as String // empty for auto
dim Headers() as String
Headers.Append(“x-amz-acl: public-read”)
Results.AddRow(Path)
d.OptionURL = “https://s3-” + Region + “.amazonaws.com” + Path
call d.SetupAWS(AWSAccessKeyId, AWSSecretAccessKey, Region, Service, Path, Domain, Verb, HashedPayload, Headers())

e=d.Perform
Results.AddRow(“https://s3-” + Region + “.amazonaws.com” + Path)
Results.addrow "Result: "+str(e)

dim DebugMessage as string = d.DebugData // check in debugger on error
dim OutputData as string = d.OutputData
dim HTTPResult as integer = d.GetInfoResponseCode
if e <> 0 and HTTPResult <> 200 then
break
end if
bs.Close
end if
[/code]

I have also tried:

[code]dim d as UploadCURL
dim f as FolderItem = FileList.RowTag(0)
if FolderExists(f) then
dim e as integer
'dim bs as BinaryStream = BinaryStream.Open(f)

d = new UploadCURL
'd.stream = bs
'd.OptionInFileSize = bs.Length
'd.OptionUpload = True
'd.OptionVerbose = True
'd.CollectDebugData = True

// this is the image data to upload
'd.InputData = p.GetData(picture.FormatJPEG, picture.QualityHigh)
call d.OpenMTInputFile(f)

dim AWSAccessKeyId as String = “<>”
dim AWSSecretAccessKey as String = “<>”
dim Region as String = “us-west-2”
dim BucketName as string = “<>”
dim d2 as new Date
dim FileName as string = d2.SortableString + “_” + f.DisplayName
dim Service as String = “s3”
dim Path as String = “/” + BucketName + “/” + Filename
dim Domain as String // empty for auto
dim Verb as String = “PUT”
dim HashedPayload as String // empty for auto
dim Headers() as String
Headers.Append(“x-amz-acl: public-read”)
Results.AddRow(Path)
d.OptionURL = “https://s3-” + Region + “.amazonaws.com” + Path
call d.SetupAWS(AWSAccessKeyId, AWSSecretAccessKey, Region, Service, Path, Domain, Verb, HashedPayload, Headers())

e=d.PerformMT
Results.AddRow(“https://s3-” + Region + “.amazonaws.com” + Path)
Results.addrow "Result: "+str(e)

dim DebugMessage as string = d.DebugData // check in debugger on error
dim OutputData as string = d.OutputData
dim HTTPResult as integer = d.GetInfoResponseCode
if e <> 0 and HTTPResult <> 200 then
break
end if
'bs.Close
end if[/code]

Well what kind of error / response are you getting?

I am getting the following:

[code] Trying 52.218.144.28…
TCP_NODELAY set
Connected to s3-us-west-2.amazonaws.com (52.218.144.28) port 443 (#0)
ALPN, offering http/1.1
Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
TLSv1.2 (OUT), TLS header, Certificate Status (22):
TLSv1.2 (OUT), TLS handshake, Client hello (1):
TLSv1.2 (IN), TLS handshake, Server hello (2):
TLSv1.2 (IN), TLS handshake, Certificate (11):
TLSv1.2 (IN), TLS handshake, Server key exchange (12):
TLSv1.2 (IN), TLS handshake, Server finished (14):
TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
TLSv1.2 (OUT), TLS change cipher, Client hello (1):
TLSv1.2 (OUT), TLS handshake, Finished (20):
TLSv1.2 (IN), TLS change cipher, Client hello (1):
TLSv1.2 (IN), TLS handshake, Finished (20):
SSL connection using TLSv1.2 / ECDHE-RSA-AES128-SHA
ALPN, server did not agree to a protocol
Server certificate:
subject: C=US; ST=Washington; L=Seattle; O=Amazon.com Inc.; CN=*.s3-us-west-2.amazonaws.com
start date: Jul 18 00:00:00 2016 GMT
expire date: Oct 26 12:00:00 2017 GMT
issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=DigiCert Baltimore CA-2 G2
SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway.
PUT /<>/2017-05-25_08-24-56_As you drive up - Google Maps.pdf HTTP/1.1
host: s3-us-west-2.amazonaws.com
Authorization: AWS4-HMAC-SHA256 Credential=<>
Date: Thu, 25 May 2017 15:24:56 GMT
x-amz-acl: public-read
x-amz-content-sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
Content-Length: 257848

HTTP/1.1 505 HTTP Version not supported
Date: Thu, 25 May 17 15:24:55 GMT
Connection: close
Transfer-Encoding: chunked
x-amz-id-2: zc1N3/b209Sxj2GbbNUOQkUWCqts5n+/oOBMxmkuEK9pLn9BV0lssZW4S/N+z8A8JiRzFbKUaUqDdv5e3rcHhajAFplpIuA2
x-amz-request-id: 791A3DF5788029D4
Content-Type: application/xml

we are done reading and this is set to close, stop send
Closing connection 0
[/code]

Try url encoding your filename? There’s probably a space in there (I see there is)

Just for expediency, I have done one without any spaces and there are no spaces in the bucketname:

[code] Trying 52.218.144.48…
TCP_NODELAY set
Connected to s3-us-west-2.amazonaws.com (52.218.144.48) port 443 (#0)
ALPN, offering http/1.1
Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
TLSv1.2 (OUT), TLS header, Certificate Status (22):
TLSv1.2 (OUT), TLS handshake, Client hello (1):
TLSv1.2 (IN), TLS handshake, Server hello (2):
TLSv1.2 (IN), TLS handshake, Certificate (11):
TLSv1.2 (IN), TLS handshake, Server key exchange (12):
TLSv1.2 (IN), TLS handshake, Server finished (14):
TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
TLSv1.2 (OUT), TLS change cipher, Client hello (1):
TLSv1.2 (OUT), TLS handshake, Finished (20):
TLSv1.2 (IN), TLS change cipher, Client hello (1):
TLSv1.2 (IN), TLS handshake, Finished (20):
SSL connection using TLSv1.2 / ECDHE-RSA-AES128-SHA
ALPN, server did not agree to a protocol
Server certificate:
subject: C=US; ST=Washington; L=Seattle; O=Amazon.com Inc.; CN=*.s3-us-west-2.amazonaws.com
start date: Jul 18 00:00:00 2016 GMT
expire date: Oct 26 12:00:00 2017 GMT
issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=DigiCert Baltimore CA-2 G2
SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway.
PUT /<>/2017-05-25_09-27-23_Amazon.pdf HTTP/1.1
host: s3-us-west-2.amazonaws.com
Authorization: AWS4-HMAC-SHA256 Credential=<>
Date: Thu, 25 May 2017 16:27:23 GMT
x-amz-acl: public-read
x-amz-content-sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
Content-Length: 95389

We are completely uploaded and fine
HTTP/1.1 400 Bad Request
x-amz-request-id: 18DB0E850A99AB61
x-amz-id-2: SGo/RFdxRHJ71gW7NeRxLec/dsCf4saqQ5Wanyl9TZJ8mTADBlulOiqu+MnM6tmIRJKN1/UOG7k=
Content-Type: application/xml
Transfer-Encoding: chunked
Date: Thu, 25 May 2017 16:27:24 GMT
Connection: close
Server: AmazonS3

Closing connection 0
TLSv1.2 (OUT), TLS alert, Client hello (1):
[/code]

Thank you, I would have missed changing the encoding.

But, it looks like I got it, I am putting my code here for my own future reference as much as anyone else’s:

[code]dim f as FolderItem = FileList.RowTag(0)
if FolderExists(f) then
dim e as integer
dim bs as BinaryStream = BinaryStream.Open(f)
dim d as new UploadCURL
d.InputData = bs.Read(bs.Length)

d.OptionUpload = True
d.OptionVerbose = True
d.CollectDebugData = True

dim AWSAccessKeyId as String = “<>”
dim AWSSecretAccessKey as String = “<>”
dim Region as String = “us-west-2”
dim BucketName as string = “<>”
dim d2 as new Date
dim FileName as string = EncodeURLComponent(d2.SortableString(True) + “_” + f.DisplayName)
dim Service as String = “s3”
dim Path as String = “/” + BucketName + “/” + Filename
dim Domain as String // empty for auto
dim Verb as String = “PUT”
dim HashedPayload as String // empty for auto
dim Headers() as String
Headers.Append(“x-amz-acl: public-read”)
Results.AddRow(Path)

call d.SetupAWS(AWSAccessKeyId, AWSSecretAccessKey, Region, Service, Path, Domain, Verb, HashedPayload, Headers())

e=d.Perform
Results.AddRow(“https://s3-” + Region + “.amazonaws.com” + Path)
Results.addrow "Result: "+str(e)

dim DebugMessage as string = d.DebugData // check in debugger on error
DebugWindow.DebugText.Text = DebugMessage

dim OutputData as string = d.OutputData
dim HTTPResult as integer = d.GetInfoResponseCode
if e <> 0 and HTTPResult <> 200 then
break
end if
bs.Close

end if[/code]

ok, you’re on from an error 505 to an error 400, thats progress.

The body should contain xml of the error, could you post that?

Thanks for trying.
The Debug messages from curl and output data would be interesting.

Ah great, you got it working. nice nice