使用Curl向Google云存储发布请求 [英] POST request to google cloud storage using Curl

查看:218
本文介绍了使用Curl向Google云存储发布请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以下 Curl 命令中,内容类型和内容长度以及访问载体都附加到了我的存储桶URI,以将文件上传到Google云存储.

In the following Curl command, content type and content length and access bearer are attached to my bucket URI to upload a file to google cloud storage.

C:\softwares\curl>curl -X POST -H "Content-Type:application/json" \
    -H "Content-Length:100" \
    -H "Authorization: Bearer <MY_OAUTH2_TOKEN>" \ 
    "https://www.googleapis.com/upload/storage/v1/b/kids-74096.appspot.com/o?uploadType=media&name=newcurl" \
    -d '{"text":"something"}'

但是我收到此错误:

卷曲:(92)未彻底关闭HTTP/2流1:PROTOCOL_ERROR(错误1)

curl: (92) HTTP/2 stream 1 was not closed cleanly: PROTOCOL_ERROR (err 1)

推荐答案

确保包含Content-Type标头,并确保Content-Length与要发送的数据长度匹配.这是一个示例:

Make sure to include a Content-Type header, and ensure that your Content-Length matches the length of the data you're sending. Here's an example:

curl -k -v -X POST \
-H "Authorization: Bearer <your_oauth2_token>" -H "Content-Length: 8" \
-H "Content-Type: text/plain" \
'https://www.googleapis.com/upload/storage/v1/b/your-bucket/o?uploadType=media&name=yourobjectname' \
-d 'yourdata'

如评论中所建议,您可能会发现更容易使用 gsutil 或Cloud Storage 客户端库来实现.

As suggested in the comments, you might find it easier to use gsutil or the Cloud Storage client libraries to accomplish this.

这篇关于使用Curl向Google云存储发布请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆