第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 golang 中編碼 POST 策略 - 基于瀏覽器的上傳到亞馬遜 S3?

如何在 golang 中編碼 POST 策略 - 基于瀏覽器的上傳到亞馬遜 S3?

C#
慕尼黑5688855 2021-11-15 16:41:03
我正在嘗試將圖像文件上傳到亞馬遜 s3。設(shè)置如下:Web 服務(wù)器:golang前端:用于測試的簡單html表單參考本文檔:http : //docs.aws.amazon.com/AmazonS3/latest/API/sigv4-post-example.html我參考了上面文檔中提供的示例并嘗試了這個:http ://play.golang.org/p/3zn5fSDasK  package main  import "fmt"  import "encoding/base64"  func main() {         bytePolicy := []byte(`{                     "expiration": "2013-08-06T12:00:00.000Z",                    "conditions": [                             {"bucket": "examplebucket"},                             ["starts-with", "$key", "user/user1/"],                             {"acl": "public-read"},                             {"success_action_redirect": "http://acl6.s3.amazonaws.com/successful_upload.html"},                             ["starts-with", "$Content-Type", "image/"],                             {"x-amz-meta-uuid": "14365123651274"},                             ["starts-with", "$x-amz-meta-tag", ""],                             {"x-amz-credential":"AKIAIOSFODNN7EXAMPLE/20130806/us-east-1/s3/aws4_request"},                             {"x-amz-algorithm": "AWS4-HMAC-SHA256"},                             {"x-amz-date": "20130806T000000Z" }                      ]                  }`)        fmt.Println(base64.StdEncoding.EncodeToString(bytePolicy)) }為什么我的 base64 編碼策略與亞馬遜的策略不匹配?
查看完整描述

1 回答

?
HUH函數(shù)

TA貢獻(xiàn)1836條經(jīng)驗 獲得超4個贊

僅僅是因為產(chǎn)生這些 base64 字符串的 2 個 JSON 源文本具有不同的縮進(jìn)和不同的內(nèi)容,如下所示(它們不等于逐個字符)。


解碼這兩個 base64 字符串,您將看到差異。你可以用一個程序(不一定是 Go)來做到這一點,或者簡單地使用像這樣的在線服務(wù)。


您不應(yīng)該擔(dān)心縮進(jìn),這在 JSON 中無關(guān)緊要。但是,當(dāng)您使用 Base64 對文本進(jìn)行編碼時,會對源的所有字符進(jìn)行編碼,包括用于縮進(jìn)的空格和制表符,因此不同的縮進(jìn)將導(dǎo)致不同的 Base64 編碼形式。


但是對比2個解碼的JSON,還有其他的不同:


第一:


"expiration": "2013-08-06T12:00:00.000Z"

"success_action_redirect": "http://acl6.s3.amazonaws.com/successful_upload.html"

第二個:


"expiration": "2013-08-07T12:00:00.000Z"

"success_action_redirect": "http://examplebucket.s3.amazonaws.com/successful_upload.html"

完整解碼的 JSON 文本:


第一個:


                        "expiration": "2013-08-06T12:00:00.000Z",

                        "conditions": [

                                 {"bucket": "examplebucket"},

                                ["starts-with", "$key", "user/user1/"],

                                 {"acl": "public-read"},

                                 {"success_action_redirect": "http://acl6.s3.amazonaws.com/successful_upload.html"},

                                ["starts-with", "$Content-Type", "image/"],

                                {"x-amz-meta-uuid": "14365123651274"},

                                ["starts-with", "$x-amz-meta-tag", ""],


                                {"x-amz-credential":"AKIAIOSFODNN7EXAMPLE/20130806/us-east-1/s3/aws4_request"},

                                {"x-amz-algorithm": "AWS4-HMAC-SHA256"},

                               {"x-amz-date": "20130806T000000Z" }

                          ]

                    }

第二個:


{ "expiration": "2013-08-07T12:00:00.000Z",

  "conditions": [

    {"bucket": "examplebucket"},

    ["starts-with", "$key", "user/user1/"],

    {"acl": "public-read"},

    {"success_action_redirect": "http://examplebucket.s3.amazonaws.com/successful_upload.html"},

    ["starts-with", "$Content-Type", "image/"],

    {"x-amz-meta-uuid": "14365123651274"},

    ["starts-with", "$x-amz-meta-tag", ""],


    {"x-amz-credential": "AKIAIOSFODNN7EXAMPLE/20130806/us-east-1/s3/aws4_request"},

    {"x-amz-algorithm": "AWS4-HMAC-SHA256"},

    {"x-amz-date": "20130806T000000Z" }

  ]

}


查看完整回答
反對 回復(fù) 2021-11-15
  • 1 回答
  • 0 關(guān)注
  • 236 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號