douxian4323 2015-05-27 21:27
浏览 29

将二进制数据的Blob发送给dynamodb时出错

I'm running into an issue with attempting to manage a dynamodb instance using godynamo.

My code is meant to take a gob encoded byte array and put it into dynamodb.

func (c *checkPointManager) CommitGraph(pop *Population) {
    var blob, err = pop.GobEncodeColorGraphs()
    fitness := pop.GetTotalFitness()
    if err != nil {
            log.Fatal(err)
    }

    put1 := put.NewPutItem()
    put1.TableName = "CheckPoint"
    put1.Item["fitnessScore"] = &attributevalue.AttributeValue{N: string(fitness)}
    put1.Item["population"] = &attributevalue.AttributeValue{N: string(1)}
    put1.Item["graph"] = &attributevalue.AttributeValue{B: string(blob)}
    body, code, err := put1.EndpointReq()
    if err != nil || code != http.StatusOK {
            log.Fatalf("put failed %d %v %s
", code, err, body)
    }
    fmt.Printf("values checkpointed:  %d
 %v
 %s
", code, err, body)

}

Every time I run this code though, I get the following error. can not be converted to a Blob: Base64 encoded length is expected a multiple of 4 bytes but found: 25

Does godynamo not handle making sure a binary array specifically converts to base64? Is there an easy way for me to handle this issue?

  • 写回答

1条回答 默认 最新

  • doushouhe7072 2015-05-28 06:04
    关注

    "Client applications must encode binary values in base64 format" according to the binary data type description of Amazon DynamoDB Data Types.

    Your code could encode the value if you want, see golang's base64 package: https://golang.org/pkg/encoding/base64

    The godynamo library provides functions that will encode it for you, have a look at AttributeValue:

        // InsertB_unencoded adds a new plain string to the B field.
        // The argument is assumed to be plaintext and will be base64 encoded.
        func (a *AttributeValue) InsertB_unencoded(k string) error {
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据