我正在尝试使用 Soundcloud API ( https://developers.soundcloud.com/docs/api/reference#tracks ) 将音频文件上传到 Soundcloud。我必须传入文件的参数需要“音频文件的二进制数据”,我不确定如何在 Go 中加载这样的东西。我目前的代码如下,但音频文件当然不能正常发送。buf := new(bytes.Buffer)w := multipart.NewWriter(buf)label, err := w.CreateFormField("oauth_token")if err != nil { return err}label.Write([]byte(c.Token.AccessToken))fw, err := w.CreateFormFile("upload", "platform/young.mp3")if err != nil { return err}fd, err := os.Open("platform/young.mp3")if err != nil { return err}defer fd.Close()_, err = io.Copy(fw, fd)if err != nil { return err}w.Close()req, err := http.NewRequest("POST", "https://api.soundcloud.com/tracks.json", buf)if err != nil { return err}req.Header.Set("Content-Type", w.FormDataContentType())req.SetBasicAuth("email@email.com", "password")fmt.Println(req.Form)res, err := c.Client.Do(req)if err != nil { return err}
1 回答
- 1 回答
- 0 关注
- 195 浏览
添加回答
举报
0/150
提交
取消