dream0776 2019-04-11 13:28
浏览 98
已采纳

无法将文件上传到生产中的Google云存储

I'm following this documentation to upload files to GCS. Setting Up Authentication for Server to Server Production Applications

It works in local but in production i get this error:

Post https://www.googleapis.com/upload/storage/v1/b/[bucket-name]/o?alt=json&prettyPrint=false&projection=full&uploadType=multipart: x509: failed to load system roots and no roots provided.

func UploadIMG(ctx *context.Context, file []byte, fileName string) error {
    storageClient, err := storage.NewClient(*ctx)
    if err != nil {
        log.Fatal(err)
    }
    w := storageClient.Bucket(bucketName).Object(fileName).NewWriter(*ctx)
    if _, err := w.Write(file); err != nil {return err}
    if err := w.Close(); err != nil {return err}

    oauthClient, err := google.DefaultClient(*ctx, cloudkms.CloudPlatformScope)
    if err != nil {
        log.Fatal(err)
    }

    kmsService, err := cloudkms.New(oauthClient)
    if err != nil {
        log.Fatal(err)
    }

    _ = kmsService

    return nil
}
  • 写回答

3条回答 默认 最新

  • dongshuohuan5291 2019-04-14 13:17
    关注

    as guys said in their answers, it's related to missing Certificate Authority in my dockerFile.

    In my case, in alpine there is already a package utility called ca-certificates which comes with its preinstalled certs. Just needed to add the following command to my docker.

    RUN apk --no-cache add ca-certificates
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条