Amazon S3 Classic Asp 파일 업로드 테스트 정보 입니다.
해당 정보를 조금 수정해서 사용하면, S3에 파일 업로드를 쉽게 할수 있겠죠
S3Upload.asp
<script language="javascript" runat="server"> function GMTNow(){return new Date().toGMTString()} </script> <% Const AWS_BUCKETNAME = "wowtvbucket" Const AWS_ACCESSKEY = "AKIAJXXALEE3A5UPOHOQ" Const AWS_SECRETKEY = "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" LocalFile = Server.Mappath("/004_1920x1200.jpg") Dim sRemoteFilePath sRemoteFilePath = "/files/test.jpg" Dim strNow strNow = GMTNow() ' GMT 정보 호출 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 = "https://" & AWS_BUCKETNAME & ".s3.amazonaws.com" With Server.CreateObject("MSXML2.ServerXMLHTTP.6.0") .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) With Server.CreateObject("Adodb.Stream") .Type = 1 ' adTypeBinary .Open .LoadFromFile sPath .Position = 0 GetBytes = .Read .Close End With 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 %> |
'▣ ASP ▣' 카테고리의 다른 글
Microsoft VBScript runtime error '800a01ad' 오류 해결 방법 (0) | 2012.07.10 |
---|---|
[asp]내부/외부 SMTP를 이용한 메일 보내기 (0) | 2011.08.12 |
[ASP] 캐시(Cache) 제거 / 기타 정보 (0) | 2009.11.24 |
AJAX 폼데이터 전송시 한글 깨짐 현상 해결 방법 (0) | 2009.11.23 |
AJAX 폼데이터 전송시 한글 깨짐 현상 최종판 (2) | 2009.11.23 |