在 ASP.NET 中使用 C# 在 Dropbox 上上传文件
Uploading files on Dropbox using C# in ASP.NET
RequestResult strReq = OAuthUtility.Put(
"https://content.dropboxapi.com/1/files_put/auto/",
new HttpParameterCollection {
{"access_token",MYAccessToken},
{"path",Path.Combine(this.CurrentPath, Path.GetFileName(@"C:\test\jj.kk\Downloads90480.jpg")).Replace("\","/")},
{"overwrite","true"},
{"autorename","true"}
}
);
我正在使用上面的代码在 Dropbox 上上传文件,但出现以下错误:
The remote server returned an error: (400) Bad Request.
RequestResult : { "error": "Content-Type (application/x-www-form-urlencoded) may not be one of (\'application/x-www-form-urlencoded\', \'multipart/form-data\')" }
Httpheader :
{Transfer-Encoding: chunked
Connection: keep-alive
X-Dropbox-Request-Id: 4029d2ae041cf1f25d8f58d06d158b83
X-Robots-Tag: noindex, nofollow, noimageindex
Content-Type: application/json
Date: Fri, 07 Oct 2016 15:24:17 GMT
Server: nginx
}
在 ASP.NET 中还有其他方法可以在 Dropbox 上上传文件吗?
您收到的错误消息表明您的 API 请求的问题是 Content-Type
具有意外值。也就是说,您(大概是通过您正在使用的库)正在发送 application/x-www-form-urlencoded
。这不是 Dropbox API /1/files_put endpoint 允许的格式,它需要请求正文中的原始文件数据。
虽然要回答您的实际问题,但在 ASP.NET 中还有另一种上传到 Dropbox 的方法。您可以使用 Dropbox API v2,而不是此处使用的 Dropbox API v1。 (实际上你应该这样做,因为 Dropbox API v1 is deprecated。)
为此,我们强烈建议使用官方 SDK:
https://www.dropbox.com/developers/documentation/dotnet
或者,您可以直接使用 HTTP 端点,例如:
https://www.dropbox.com/developers/documentation/http/documentation#files-upload
RequestResult strReq = OAuthUtility.Put(
"https://content.dropboxapi.com/1/files_put/auto/",
new HttpParameterCollection {
{"access_token",MYAccessToken},
{"path",Path.Combine(this.CurrentPath, Path.GetFileName(@"C:\test\jj.kk\Downloads90480.jpg")).Replace("\","/")},
{"overwrite","true"},
{"autorename","true"}
}
);
我正在使用上面的代码在 Dropbox 上上传文件,但出现以下错误:
The remote server returned an error: (400) Bad Request.
RequestResult : { "error": "Content-Type (application/x-www-form-urlencoded) may not be one of (\'application/x-www-form-urlencoded\', \'multipart/form-data\')" }
Httpheader : {Transfer-Encoding: chunked Connection: keep-alive X-Dropbox-Request-Id: 4029d2ae041cf1f25d8f58d06d158b83 X-Robots-Tag: noindex, nofollow, noimageindex Content-Type: application/json Date: Fri, 07 Oct 2016 15:24:17 GMT Server: nginx }
在 ASP.NET 中还有其他方法可以在 Dropbox 上上传文件吗?
您收到的错误消息表明您的 API 请求的问题是 Content-Type
具有意外值。也就是说,您(大概是通过您正在使用的库)正在发送 application/x-www-form-urlencoded
。这不是 Dropbox API /1/files_put endpoint 允许的格式,它需要请求正文中的原始文件数据。
虽然要回答您的实际问题,但在 ASP.NET 中还有另一种上传到 Dropbox 的方法。您可以使用 Dropbox API v2,而不是此处使用的 Dropbox API v1。 (实际上你应该这样做,因为 Dropbox API v1 is deprecated。)
为此,我们强烈建议使用官方 SDK:
https://www.dropbox.com/developers/documentation/dotnet
或者,您可以直接使用 HTTP 端点,例如:
https://www.dropbox.com/developers/documentation/http/documentation#files-upload