LargeFileUploadTask fails on open-ended ranges ("0-") and BatchRequestStep drops request headers
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 64/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- node.js, typescript
- Lĩnh vực
- api
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
Two bugs in @microsoft/msgraph-sdk-core:
-
LargeFileUploadTask.getRangesRemainingsplits each entry innextExpectedRangeson"-"and runsparseInt(rangeArray[1], 10). GraphcreateUploadSessionresponses return open-ended ranges such as["0-"](https://learn.microsoft.com/en-us/graph/api/driveitem-createuploadsession?view=graph-rest-1.0), which turnsrange[1]intoNaN. Inupload(),while (currentRangeBegin <= range[1])is immediatelyfalse, so zero slices are sent andupload()throwsError("Upload failed"). -
convertRequestInformationToBatchIteminsrc/content/BatchRequestStep.tschecksif (headers !== undefined)whileheadersis still uninitialized (undefined), soBatchRequestContent.addBatchRequestalways creates steps withheaders: undefined. Per-step headers (Content-Type,Prefer,ConsistencyLevel) are lost, andserializeBatchItemnever seesContent-Type: application/json, so JSON request bodies are base64-encoded viawriteByteArrayValue. In addition, ifstep.headersis populated manually with"Content-Type": "application/json",serializeBatchItemcallswriter.writeObjectValue("headers", ...)andwriter.writeObjectValue("body", ...)without a serializer callback, emitting"headers":{}and"body":{}.
Expected behavior
LargeFileUploadTaskhandles open-ended ranges such as"0-"and"327680-"up to the end of the upload stream, matching the comment ingetRangesRemaining.BatchRequestContent.addBatchRequestcopies headers fromRequestInformationontoBatchRequestStep, andserializeBatchItemserializesheadersand JSONbodyvalues into the$batchrequest 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)returnsNaNwhen the end offset is omitted; note also thatUploadSliceneeds the total byte length forContent-Range).src/content/BatchRequestStep.ts: inconvertRequestInformationToBatchItem,if (headers !== undefined)tests the uninitialized local instead ofrequestInformation.headers, andrequestInformation.headers.entries()yieldsSet<string>values rather than plain strings; inserializeBatchItem,writer.writeObjectValueis called without a serializer callback such as(_, v) => writer.writeAdditionalData(v).
Credit: https://ucsbplse.github.io/
- Ngôn ngữ chính
- TypeScript
- Star
- 3
- Fork
- 7
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của microsoftgraph/msgraph-sdk-typescript-core
-
enhancement Standard GitHub label
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
-
enhancement Standard GitHub label
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
Tất cả issue của microsoftgraph/msgraph-sdk-typescript-core
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
fb55/htmlparser2#2579 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug good first issue needs-review
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 83/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Add Module DB RulesĐang mởdocumentation public
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 68/100
midnightntwrk/umbradb#65 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
area/channels kind/bug priority/medium
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
nanocoai/nanoclaw#4501 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Docker images: plain X.Y.Z tag (e.g. 7.2.3) is never updated after the initial release buildĐang mởneeds verification
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 13 ngày