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 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示