我正在使用 Box API v2,我尝试使用 WebClient 上传文件但没有成功。
从 API:
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
所以我用 C# 写了它:
using (WebClient client = new WebClient())
{
client.Headers.Add("Authorization", "Bearer " + Utils.GetAccessTokenFromFile());
client.Headers.Set("Content-Type", "multipart/form-data; boundary=-handeptrai---");
NameValueCollection values = new NameValueCollection() {
{"attributes","{\"name\":\"test.txt\", \"parent\":{\"id\":\"0\"}}"},
{"file",@Utils.TestFilePath}
};
byte[] result = client.UploadValues("https://upload.box.com/api/2.0/files/content", "POST", values);
string json = Encoding.UTF8.GetString(result);
}
当我尝试调试以查看发生了什么时,我在 UploadValues 步骤中什么也没看到。
任何想法?谢谢!