Klassische ASP-amazon s3 rest-Zulassung

Ich verwirrt bin, was mache ich hier falsch...

<script language="javascript" runat="server">
  function GMTNow(){return new Date().toGMTString()}
</script>
<%

Const AWS_BUCKETNAME = "uk-bucketname"
Const AWS_ACCESSKEY = "GOES HERE"
Const AWS_SECRETKEY = "SECRET"
LocalFile = Server.Mappath("/test.jpg")

Dim sRemoteFilePath
    sRemoteFilePath = "/files/test.jpg" 'Remote Path, note that AWS paths (in fact they aren't real paths) are strictly case sensitive

Dim strNow
    strNow = GMTNow() ' GMT Date String

Dim StringToSign
    StringToSign = Replace("PUT\n\nimage/jpeg\n\nx-amz-date:" & strNow & "\n/"& AWS_BUCKETNAME & sRemoteFilePath, "\n", vbLf)

Dim Signature
    Signature = BytesToBase64(HMACSHA1(AWS_SECRETKEY, StringToSign))

Dim Authorization
    Authorization = "AWS " & AWS_ACCESSKEY & ":" & Signature

Dim AWSBucketUrl
    AWSBucketUrl = "http://s3.amazonaws.com/" & AWS_BUCKETNAME

With Server.CreateObject("Microsoft.XMLHTTP")
    .open "PUT", AWSBucketUrl & sRemoteFilePath, False
    .setRequestHeader "Authorization", Authorization
    .setRequestHeader "Content-Type", "image/jpeg"
    .setRequestHeader "Host", AWS_BUCKETNAME & ".s3.amazonaws.com"  
    .setRequestHeader "x-amz-date", strNow
    .send GetBytes(LocalFile) 'Get bytes of local file and send
    If .status = 200 Then ' successful
        Response.Write "<a href="& AWSBucketUrl & sRemoteFilePath &" target=_blank>Uploaded File</a>"
    Else ' an error ocurred, consider xml string of error details
        Response.ContentType = "text/xml"
        Response.Write .responseText
    End If
End With

Function GetBytes(sPath)
    dim fs,f
set fs=Server.CreateObject("Scripting.FileSystemObject")
set f=fs.GetFile(sPath)
GetBytes = f.Size
set f=nothing
set fs=nothing
End Function

Function BytesToBase64(varBytes)
    With Server.CreateObject("MSXML2.DomDocument").CreateElement("b64")
        .dataType = "bin.base64"
        .nodeTypedValue = varBytes
        BytesToBase64 = .Text
    End With
End Function

Function HMACSHA1(varKey, varValue)
    With Server.CreateObject("System.Security.Cryptography.HMACSHA1")
        .Key = UTF8Bytes(varKey)
        HMACSHA1 = .ComputeHash_2(UTF8Bytes(varValue))
    End With
End Function

Function UTF8Bytes(varStr)
    With Server.CreateObject("System.Text.UTF8Encoding")
        UTF8Bytes = .GetBytes_4(varStr)
    End With
End Function
%>

Jetzt immer der Fehler.

msxml3.dll error '800c0008'

The download of the specified resource has failed.

/s3.asp, line 39
  • Hast du es geschafft, zu finden, Ihr problem, Chris?
  • Nein noch nicht 🙁
  • Hallo Chris, bist du angemeldet für den Amazon S3 service als auch ein AWS-Konto? das ist der thread forums.aws.amazon.com/thread.jspa?threadID=45582
  • Ja, ich habe einen Eimer set-up und bereit zu gehen 🙂
  • +1 für den Mut, kombiniert innovatives cloud-tech mit stone age ASP-tech. Hoffe, du findest eine gute Lösung.
  • Definieren Sie die vollständige relative Pfad in sRemoteFilePath als /files/test.jpg. GetBytes geändert wurde, falsch. Es muss wieder bytes der Datei, nicht Größe Byte. Ich werde aktualisieren, meine Antwort mit diesen Verbesserungen, wie Sie benötigen Strom. Als Ausgangspunkt, kopieren Sie einfach und verwenden Sie nach dem ändern der S3-Anmeldeinformationen.
  • Ich habe aktualisiert mein code, das problem ist dass Sie mir. "The requested header was not found" Problem code ist .send GetBytes(LocalFile)
  • Das ist mit MSXML2.ServerXMLHTTP.3.0 wenn ich 6.0 bekomme ich The HTTP redirect request failed gleichen Zeile code.

Schreibe einen Kommentar