小编Bin*_*sh 的帖子

如何使用 Microsoft Graph API rest 调用在 c# 中上传大型文档

我正在使用外部 .Net Web 应用程序,想知道如何使用 Microsoft Graph 将大文件上传到文档库。我最多可以上传 4mb,但高于它的任何内容都会引发错误。

我知道有一个createUploadSession但是不确定如何实现它。任何帮助将不胜感激。

这是我为成功上传高达 4mb 所做的工作:

string requestUrl =
    "https://graph.microsoft.com/v1.0/drives/{mydriveid}/items/root:/" +
    fileName + ":/content";

HttpClient Hclient = new HttpClient();

HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Put, requestUrl);

message.Content = new StreamContent(file.InputStream);

client.DefaultRequestHeaders
    .TryAddWithoutValidation("Content-Type",
        "application/json; odata=verbose; charset=utf-8");

HttpResponseMessage Hresponse = await client.SendAsync(message);

//if the response is 200 then read the response and retrive the GUID!
if (Hresponse.IsSuccessStatusCode)
{
    responseString = await
    Hresponse.Content.ReadAsStringAsync();
    JObject jDataRetrieved = JObject.Parse(responseString);
    strGuid = jDataRetrieved.SelectToken("eTag").ToString();

}
Run Code Online (Sandbox Code Playgroud)

c# onedrive microsoft-graph-api

3
推荐指数
2
解决办法
4560
查看次数

标签 统计

c# ×1

microsoft-graph-api ×1

onedrive ×1