正如标题所述,我正在尝试将生成的大量内存文件上传到 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
变量的值。
好吧,经过一番研究我认为这是不可行的。 Microsoft SDK 中的 GraphService 接受 InputStream,但深入研究代码表明他需要确切的文件大小来上传它。也许正确的参数应该是 FileInputStream 或 ByteArrayInputStream。