doujing5726 2018-06-18 05:07 采纳率: 0%
浏览 13
已采纳

云存储:使用golang在本地时无法上传任何内容

I have this piece of code:

ctx:=context.Background()
    cliente, err := storage.NewClient(ctx)
    if err != nil {
        log.Fatal(err)
    }
    clienteCS := cliente.Bucket("prueba123456789")
    w:=clienteCS.Object("prueba").NewWriter(ctx)
    w.ContentType = "text/plain"
    if _, err := w.Write([]byte("abcde
")); err != nil {
           log.Fatal(err)
    }
    attrs, err := clienteCS.Attrs(ctx)
    fmt.Printf("atrr: %+v   err:%v
",attrs,err)

When I run this program, in the console I can see the attributes printed from my bucket, that would mean for me that there is nothing wrong with the configuration console , but the problem is that when I see on console.cloud.google.com I see no file on my bucket my bucket even on api dashboard does not seem like any api has been called(that peak before the red line is other api I was using) api dashboard, even though no error is showing on my console that could indicate something went wrong

  • 写回答

1条回答 默认 最新

  • doulu8537 2018-06-18 09:33
    关注

    I just forgot about closing the client, this page alert this problem, always must close the client or the file won't be send, so just need to add some lines:

    if err := w.Close(); err != nil {
                log.Fatal(err)
                return
            }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题