我正在尝试使用LargFileUploadTask将大于4MB的文件上传到Sharepoint列表中的文件夹中。代码似乎在"cities“文件夹中的PostAsync之后创建临时文件。我看到创建了一个文件,即~tmphamilton.png。但当UploadAsync被调用时,它会失败,并返回“资源无法找到”
当我在创建uploadSession时删除文件夹路径时,代码工作正常
你知道我可能做错了什么吗?
// create an upload session
var uploadSession = await graphClient.Sites("site id").Drive().Root().ItemWithPath("cities\hamilton.png").CreateUploadSession().Request().PostAsync();
var maxSliceSize = 320 * 1024; // 320 KB - Change this to your slice size. 5MB is the default.
var largeFileUploadTask = new LargeFileUploadTask(uploadSession, stream, maxSliceSize);
// upload away with relevant callback
DriveItem itemResult = await largeFileUploadTask.UploadAsync( progress );
发布于 2020-09-18 22:03:58
确保最大。WebApplication中的上载大小设置大于文件大小。根据上传位置和SharePoint版本的不同,大小可能小于50MB。在本地,可以在CentralAdmin->Application Management->Web Application xy->General Settings中进行设置
发布于 2020-10-13 22:49:34
您是否能够成功地将文件上载到文档库的根目录?请参阅下面的代码。
string siteId = WebConfigurationManager.AppSettings.Get("SiteId");
string libraryName = WebConfigurationManager.AppSettings.Get("LibraryName");
string fileName = filePath.Substring(filePath.LastIndexOf("\\") + 1);
var uploadSession = await graphServiceClient.Sites[siteId].Lists[libraryName].Drive.Root
.ItemWithPath(fileName)
.CreateUploadSession(uploadProps)
.Request()
.PostAsync();
发布于 2021-04-27 21:38:48
它确实适用于Graph 3.1.4和Java,我花了一段时间才让它工作,但它上传的文件>4MB相当性能…
// itemPath类似于"/myFolder/DailyUpload/“
public CompletableFuture UploadFileToSharePoint(String idSite, String parentId, String itemPath, String fileName, InputStream file) {
final List<Option> options = new LinkedList<Option>();
try {
return mClient
.sites(idSite)
.drive()
.root()
.itemWithPath(itemPath+ Build.ID.toUpperCase()+"/"+fileName)
.createUploadSession(
DriveItemCreateUploadSessionParameterSet.newBuilder()
.withItem(new DriveItemUploadableProperties())
.build())
.buildRequest(options)
.postAsync().thenCompose(uploadSession -> {
byte[] data = null;
try {
byte[] buff = new byte[file.available()];
int bytesRead = 0;
ByteArrayOutputStream bao = new ByteArrayOutputStream();
while ((bytesRead = file.read(buff)) != -1) {
bao.write(buff, 0, bytesRead);
}
data = bao.toByteArray();
}
catch (IOException e) {
e.printStackTrace();
}
if (data != null && data.length>0) {
final InputStream uploadFile = new ByteArrayInputStream(data); //"{\"hehe\":\"haha\"}".getBytes(StandardCharsets.UTF_8));
try {
final long fileSize = (long) uploadFile.available();
LargeFileUploadTask<DriveItem> largeFileUploadTask = new LargeFileUploadTask<DriveItem>(uploadSession,
mClient, uploadFile, fileSize, DriveItem.class);
// If everything is fine, the procedure returns a DriveItem with the item already
return largeFileUploadTask.uploadAsync();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
});
}
catch (IndexOutOfBoundsException e) {
Log.d("GraphHelper", "UploadFileToSharePoint failed: "+ e.getMessage());
return CompletableFuture.completedFuture(false);
}
}
希望这对其他人有帮助
https://stackoverflow.com/questions/63909760
复制相似问题