使用 Java Graph SDK 使用 PipedStream 将文件上传到 SharePoint 会导致错误“Content-Range 标头丢失或格式错误”

问题描述 投票:0回答:1

正如标题所述,我正在尝试将生成的大量内存文件上传到 SharePoint。为了节省内存,我尝试使用 PipedStream 上传它,但我有一个例外,原因是:

com.microsoft.graph.core.ClientException: Error code: invalidRequest
Error message: The Content-Range header is missing or malformed.

我的上传电话是:

LargeFileUploadTask<DriveItem> largeFileUploadTask = new LargeFileUploadTask<>(uploadSession, msGraphServiceClient,
      inputStream, streamSize, DriveItem.class);

    try {
      LargeFileUploadResult<DriveItem> uploadResults = largeFileUploadTask.upload(CHUNK_SIZE, null, (current,
        max) -> log.debug(String.format("Uploaded %d bytes of %d total bytes", current, max)));

      return uploadResults.location;
    } catch (IOException e) {
      throw new IllegalArgumentException("File upload failed.", e);
    }

是否可以将文件作为流上传,或者我之前需要知道确切的文件大小吗? 那是因为我不知道

streamSize
变量的值。

java sharepoint stream
1个回答
0
投票

好吧,经过一番研究我认为这是不可行的。 Microsoft SDK 中的 GraphService 接受 InputStream,但深入研究代码表明他需要确切的文件大小来上传它。也许正确的参数应该是 FileInputStream 或 ByteArrayInputStream。

© www.soinside.com 2019 - 2024. All rights reserved.