0

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\n", code, err, body)
    }
    fmt.Printf("values checkpointed:  %d\n %v\n %s\n", 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?

Daniel Imberman
  • 618
  • 1
  • 5
  • 18

1 Answers1

0

"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 {
Mark
  • 6,731
  • 1
  • 40
  • 38