将文件上传到Dropbox时会出现方法错误

时间:2013-01-30 07:31:17

标签: file-upload oauth dropbox

使用以下网址使用oauth将文件上传到dropbox并收到错误消息 {“error”:“调用需要以下方法之一:PUT,POST,得到GET!”} 我将httpmethod作为PUT传递,但仍在询问错误。

用于上传的签名是

https://api-content.dropbox.com/1/files_put/dropbox/test?oauth_consumer_key=twcek2m7cxtantc&oauth_signature_method=PLAINTEXT&oauth_token=918v4lxg2w23car&oauth_version=1.0&oauth_signature=fbs34nykryouuj1%26rbbprgh95tjzf22

使用这个得到错误

{“error”:“调用需要以下方法之一:PUT,POST,得到GET!”}

请告诉我任何人如何解决此错误。

public FileSystemInfo UploadFile(string root, string path, string file)
        {
            var uri = new Uri(new Uri(DropboxRestApi.ApiContentServer),
                String.Format("files_put/{0}/{1}",
                root, UpperCaseUrlEncode(path)));

            var oauth = new OAuth();
            //var requestUri = oauth.DownloadSignRequest(uri, _consumerKey, _consumerSecret, "POST", _accessToken);
            var requestUri = oauth.SignRequest(uri, _consumerKey, _consumerSecret, _accessToken, "PUT");

            var request = (HttpWebRequest) WebRequest.Create(requestUri);
            request.Method = WebRequestMethods.Http.Post;
            request.KeepAlive = true;

            byte[] buffer;
            using (var fileStream = new FileStream(file, FileMode.Open, FileAccess.Read))
            {
                int length = (int) fileStream.Length;
                buffer = new byte[length];
                fileStream.Read(buffer, 0, length);
            }

            request.ContentLength = buffer.Length;
            using (var requestStream = request.GetRequestStream())
            {
                requestStream.Write(buffer, 0, buffer.Length);
            }

           // request.Method = "POST";

            var response = request.GetResponse();
            var reader = new StreamReader(response.GetResponseStream());
            var json = reader.ReadToEnd();
            return ParseJson<FileSystemInfo>(json);
        }

1 个答案:

答案 0 :(得分:0)

我在保存我要上传文件的路径时犯了错误。

为路径中的保存提供相同的文件名。

就是这样。