LargeFileUploadTask fails on open-ended ranges ("0-") and BatchRequestStep drops request headers

オープン
#642 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
64/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
node.js, typescript
領域
api

調査の方向性

Two independent fixes. Start in src/tasks/LargeFileUploadTask.ts: getRangesRemaining must treat a missing end offset in "0-" as the end of the stream, and upload() must slice up to that length so UploadSlice can build Content-Range. Then in src/content/BatchRequestStep.ts, convertRequestInformationToBatchItem should read requestInformation.headers (unwrapping the Set values) and serializeBatchItem needs a serializer callback for headers and JSON body. Run the reproduction script from the issue against both paths; done means ranges are [0, size-1], slices are sent, and the $batch payload carries real headers and a JSON body.

索引モデルが issue の本文から書いたものです。

説明

Describe the bug

Two bugs in @microsoft/msgraph-sdk-core:

  1. LargeFileUploadTask.getRangesRemaining splits each entry in nextExpectedRanges on "-" and runs parseInt(rangeArray[1], 10). Graph createUploadSession responses return open-ended ranges such as ["0-"] (https://learn.microsoft.com/en-us/graph/api/driveitem-createuploadsession?view=graph-rest-1.0), which turns range[1] into NaN. In upload(), while (currentRangeBegin <= range[1]) is immediately false, so zero slices are sent and upload() throws Error("Upload failed").

  2. convertRequestInformationToBatchItem in src/content/BatchRequestStep.ts checks if (headers !== undefined) while headers is still uninitialized (undefined), so BatchRequestContent.addBatchRequest always creates steps with headers: undefined. Per-step headers (Content-Type, Prefer, ConsistencyLevel) are lost, and serializeBatchItem never sees Content-Type: application/json, so JSON request bodies are base64-encoded via writeByteArrayValue. In addition, if step.headers is populated manually with "Content-Type": "application/json", serializeBatchItem calls writer.writeObjectValue("headers", ...) and writer.writeObjectValue("body", ...) without a serializer callback, emitting "headers":{} and "body":{}.

Expected behavior
  1. LargeFileUploadTask handles open-ended ranges such as "0-" and "327680-" up to the end of the upload stream, matching the comment in getRangesRemaining.
  2. BatchRequestContent.addBatchRequest copies headers from RequestInformation onto BatchRequestStep, and serializeBatchItem serializes headers and JSON body values into the $batch request payload instead of base64 strings or empty objects.
How to reproduce
npm init -y && npm pkg set type=module
npm i @microsoft/[email protected] @microsoft/kiota-abstractions @microsoft/kiota-serialization-json
node repro.mjs

repro.mjs:

import { LargeFileUploadTask, BatchRequestContent } from "@microsoft/msgraph-sdk-core";
import { RequestInformation, HttpMethod } from "@microsoft/kiota-abstractions";
import { JsonSerializationWriterFactory } from "@microsoft/kiota-serialization-json";

// 1. LargeFileUploadTask with open-ended nextExpectedRanges ("0-")
let requests = 0;
const uploadAdapter = { send: async () => { requests++; return requests === 3 ? { id: "item1" } : {}; } };
const makeStream = () => new ReadableStream({ start(c) { c.enqueue(new Uint8Array(24)); c.close(); } });
const session = { uploadUrl: "https://example.invalid/up/abc", nextExpectedRanges: ["0-"], expirationDateTime: new Date() };

const task = new LargeFileUploadTask(uploadAdapter, session, makeStream(), 10, () => () => ({}), {});
console.log("rangesRemaining:", task.rangesRemaining);
await task.upload().catch((e) => console.log(e.message, "after", requests, "requests"));

// 2. BatchRequestContent.addBatchRequest drops headers and serializes JSON body as base64 (or {})
const writerFactory = new JsonSerializationWriterFactory();
let sentBody = "";
const batchAdapter = {
  baseUrl: "https://graph.microsoft.com/v1.0",
  getSerializationWriterFactory: () => writerFactory,
  send: async (ri) => { sentBody = new TextDecoder().decode(ri.content); return { responses: [] }; },
};

const ri = new RequestInformation(HttpMethod.POST, "{+baseurl}/me/messages");
ri.headers.add("Content-Type", "application/json");
ri.headers.add("ConsistencyLevel", "eventual");
ri.content = new TextEncoder().encode(JSON.stringify({ subject: "hi" }));

const batch = new BatchRequestContent(batchAdapter, {});
const step = batch.addBatchRequest(ri, "1");
console.log("step.headers:", step.headers);
await batch.postAsync();
console.log("postAsync payload:", sentBody);

step.headers = { "Content-Type": "application/json", ConsistencyLevel: "eventual" };
await batch.postAsync();
console.log("with step.headers set:", sentBody);

Actual output:

rangesRemaining: [ [ 0, NaN ] ]
Upload failed after 0 requests
step.headers: undefined
postAsync payload: {"requests":[{"id":"1","method":"POST","url":"/me/messages","body":"eyJzdWJqZWN0IjoiaGkifQ=="}]}
with step.headers set: {"requests":[{"id":"1","method":"POST","url":"/me/messages","headers":{},"body":{}}]}
SDK Version

1.0.0-preview.17 (also reproduced on main at a44b09d)

Latest version known to work for scenario above?

No response

Known Workarounds

For LargeFileUploadTask, rewrite session.nextExpectedRanges to ["0-<fileSize - 1>"] before constructing the task.

Debug output

No response

Configuration
  • OS: Linux x64
  • Node.js: v26.13.0
  • Not specific to OS or architecture.
Other information
  • src/tasks/LargeFileUploadTask.ts: getRangesRemaining (parseInt(rangeArray[1], 10) returns NaN when the end offset is omitted; note also that UploadSlice needs the total byte length for Content-Range).
  • src/content/BatchRequestStep.ts: in convertRequestInformationToBatchItem, if (headers !== undefined) tests the uninitialized local instead of requestInformation.headers, and requestInformation.headers.entries() yields Set<string> values rather than plain strings; in serializeBatchItem, writer.writeObjectValue is called without a serializer callback such as (_, v) => writer.writeAdditionalData(v).

Credit: https://ucsbplse.github.io/

主要言語
TypeScript
スター
3
フォーク
7
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

microsoftgraph/msgraph-sdk-typescript-core のほかの issue

microsoftgraph/msgraph-sdk-typescript-core の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。