SkyDrive REST API [英] SkyDrive REST API
本文介绍了SkyDrive REST API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想上传一个"大文件" (5到10Mb)。我想通过使用多个webrequest来实现。我得到的只是http 400。
I want to upload a "large file" (5 to 10Mb).I want to do it by using multiple webrequest. All i got is http 400.
这是我的代码:
string folderId = "folder....!112";
var path = @"D:\...\file.pdf";
var uri = string.Format("{0}{1}/files?{2}", SkyDrive.Utilities.ApiServiceUri, folderId, SkyDrive.Utilities.AccessToken);
int count = 0;
int offset = 0;
int bufferSize = 170000;
byte[] buffer = new byte[bufferSize];
using (var reader = new System.IO.FileStream(path, System.IO.FileMode.Open))
{
while (offset < reader.Length)
{
offset += reader.Read(buffer, 0, bufferSize);
count += bufferSize + 1;
var request = (HttpWebRequest)WebRequest.Create(uri);
request.Method = "POST";
request.Headers.Add("bits-packet-type", "Fragment");
request.Headers.Add("Content-Disposition", "file; filename=\"filename.pdf\"");
request.ContentType = "multipart/form-data; boundary=A300x";// "application/octet-stream";
using (var stream = request.GetRequestStream())
{
using (var writer = new System.IO.BinaryWriter(stream))
{
try
{
writer.Write("--A300x\r\n");
writer.Write(@"Content-Disposition: form-data; name=""file""; filename=""filename.pdf""\r\n");
writer.Write(@"Content-Type: application/octet-stream\r\n");
writer.Write(buffer);
writer.Write("\r\n--A300x--");
}
catch (System.IO.EndOfStreamException excep)
{
throw new ApplicationException(excep.Message);
}
}
}
using (var stream = request.GetResponse().GetResponseStream())
{
using (var responseReader = new System.IO.StreamReader(stream))
{
var response = responseReader.ReadToEnd();
Console.WriteLine(response);
}
}
}
}
有任何建议吗?
谢谢
BriceR
推荐答案
HTTP 400请求的正文中应该有一条错误消息。它说了什么?
There should have been an error message in the body of the HTTP 400 request. What did it say?
这篇关于SkyDrive REST API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文