Golang代码将文件上传到个人邮箱帐户

When I give this snippet of code in a golang program after recieving the access token:

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 get this error:

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}

Can anyone please help me to solve the method to add the attributes and the file name to upload into the box account?

urlStr should be https://upload.box.com/api/2.0/files/content

https://developers.box.com/docs/#files-upload-a-file

As they show in the docs, you may want to try out your queries using curl first:

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