当我在收到访问令牌后在golang程序中提供这段代码时:
f, err := ioutil.ReadFile("C:\\Users\\vembu\\Desktop\\hi.txt")
ioutil.WriteFile("hi.txt", f, 0x777)
r, _ := http.NewRequest("POST", urlStr, bytes.NewBuffer(f))
r.Header.Add("Authorization", "Bearer "+accessobj.Access_token)
r.Header.Add("attributes", "{\"name\":\"hi.txt\",\"parent\":{\"id\":\"3098791209\"}}")r.Header.Add("file", "hi.txt")
我收到此错误:
I face &{405 Method Not Allowed 405 HTTP/1.1 1 1 map[Allow:[GET, OPTIONS, HEAD] Content-Type:[text/html;charset=UTF-8] Content-Length:[0] Date:[Thu, 12 Mar 2015 13:07:32 GMT] Age:[0] Connection:[keep-alive] Server:[ATS]] 0xc08200b8c0 0 [] false map[] 0xc08201f2b0 0xc082060980}
任何人都可以帮我解决添加属性和文件名的方法上传到邮箱帐户吗?
答案 0 :(得分:0)
urlStr
应为https://upload.box.com/api/2.0/files/content
https://developers.box.com/docs/#files-upload-a-file
正如他们在文档中所示,您可能希望首先使用curl
尝试查询:
curl https://upload.box.com/api/2.0/files/content \
-H "Authorization: Bearer ACCESS_TOKEN" -X POST \
-F attributes='{"name":"tigers.jpeg", "parent":{"id":"11446498"}}' \
-F file=@myfile.jpg