Visual Basic Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

VB Examples

Bounced Mail
Bz2
Character Encoding
CSV
Digital Certificates
Digital Signatures
Email
FTP
HTML Conversion
HTTP
IMAP
Encryption
MHT / HTML Email
POP3
RSA
S/MIME
SFTP
SMTP
Socket
Spider
SSH
SSH Key
SSH Tunnel
String
Tar
Upload
XML
XMP
Zip Compression

More Examples...
Amazon S3
Email Object
DKIM / DomainKey
NTLM
DH Key Exchange
DSA
FileAccess
RSS
Atom
Self-Extractor
Service
Bzip2
PPMD
Deflate
LZW


VB Strings
VB Byte Array

 

 

 

 

 

 

 

Amazon S3 - Add Image (GIF) to Bucket

Download Chilkat 32-bit Zip ActiveX (.msi) (includes objects for .zip, .gz, .bz2, and .Z)

Download All 32-bit Chilkat ActiveX Components (.zip)

Download All 64-bit Chilkat ActiveX Components (.zip)

Demonstrates how to upload an image file (binary data) to an Amazon S3 bucket.

Download Chilkat FileAccess ActiveX (freeware)

Download Chilkat Crypt ActiveX

Download Chilkat HTTP ActiveX

Dim http As New ChilkatHttp
Dim success As Long
success = http.UnlockComponent("Anything for 30-day trial.")
If (success <> 1) Then
    '  Unlock failed.
    MsgBox http.LastErrorText
    Exit Sub
End If

'  We'll need this for HMAC and MD5...
Dim crypt As New ChilkatCrypt2

success = crypt.UnlockComponent("Anything for 30-day trial.")
If (success <> 1) Then
    MsgBox crypt.LastErrorText
    Exit Sub
End If

'  The HTTP component now includes a method to generate
'  the current date/time in RFC 2616 compliant format.
'  Note: The GenTimeStamp method is available as a pre-release (as of 18-June-2008).
'  It will become available in the next new version dated after
'  18-June-2008.
Dim curDateTime As String
curDateTime = http.GenTimeStamp()

Dim gifData() As Byte
Dim fac As New CkFileAccess
gifData = fac.ReadEntireFile("dude.gif")

'  This is the name of the object to be added:
Dim objName As String
objName = "NeoGif"

'  Calculate the MD5 hash of the object's content:
crypt.HashAlgorithm = "md5"
crypt.EncodingMode = "base64"
crypt.Charset = "windows-1252"
Dim md5Hash As String
md5Hash = crypt.HashBytesENC(gifData)

'  Create the string to be signed.
'  IMPORTANT:
'  If a Content-MD5 header is added (see below), then
'  you also need to include the MD5 hash of the content
'  here.
'  The content-type (image/gif) must match the content-type
'  passed to the PutBinary method (below).
Dim strToSign As String
strToSign = "PUT" & vbLf & md5Hash & vbLf & "image/gif" & vbLf & curDateTime & vbLf & "/chilkat/" & objName

'  We want SHA1 for the HMAC hash algorithm:
crypt.HashAlgorithm = "sha1"

'  These must be changed for your account:
Dim AWSAccessKeyId As String
AWSAccessKeyId = "zzzzzzzzzzzzzzzzzzzzzz"
Dim AWSSecretAccessKey As String
AWSSecretAccessKey = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"

'  Set the HMAC secret key:
crypt.SetHmacKeyString AWSSecretAccessKey

'  By setting the charset = "utf-8", the string will be converted
'  to utf-8 (internal to the Chilkat component) prior to signing:
crypt.Charset = "utf-8"

'  Indicate that Base64 output is desired:
crypt.EncodingMode = "base64"

Dim signature As String
signature = crypt.HmacStringENC(strToSign)

Dim authValue As String
authValue = "AWS " & AWSAccessKeyId & ":" & signature

'  The bucket to be used is specified in the Host header.
'  In this example, the object is added to the "chilkat" bucket:
http.SetRequestHeader "Host","chilkat.s3.amazonaws.com"

http.SetRequestHeader "Authorization",authValue
http.SetRequestHeader "Date",curDateTime

'  Do not GZIP the request body.  To send a gzip compressed
'  object, simply set this to 1
Dim bGzip As Long
bGzip = 0
'  Automatically add an MD5 hash of the request body in the HTTP header
'  (using the Content-MD5 header field).
Dim bMd5 As Long
bMd5 = 1

Dim url As String
url = "http://s3.amazonaws.com/" & objName

Dim strResponse As String
strResponse = http.PutBinary(url,gifData,"image/gif",bMd5,bGzip)
If (http.LastStatus = 200) Then

    '  Success is indicated by a response status of 200.
    MsgBox "Object added to bucket!"

    '  Let's check out the response header anyway...
    Text1.Text = Text1.Text & http.LastResponseHeader & vbCrLf

Else

    '  Failed.  Show the last request header, response header,
    '  and response body.
    Text1.Text = Text1.Text & http.LastHeader & vbCrLf
    Text1.Text = Text1.Text & "---" & vbCrLf
    Text1.Text = Text1.Text & http.LastResponseHeader & vbCrLf
    Text1.Text = Text1.Text & "---" & vbCrLf
    Text1.Text = Text1.Text & http.LastErrorText & vbCrLf

End If

© 2000-2012 Chilkat Software, Inc. All Rights Reserved.