首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Microsoft Graph Api上载文件夹中的大文件

Microsoft Graph Api上载文件夹中的大文件
EN

Stack Overflow用户
提问于 2020-09-16 04:57:00
回答 3查看 1.3K关注 0票数 0

我正在尝试使用LargFileUploadTask将大于4MB的文件上传到Sharepoint列表中的文件夹中。代码似乎在"cities“文件夹中的PostAsync之后创建临时文件。我看到创建了一个文件,即~tmphamilton.png。但当UploadAsync被调用时,它会失败,并返回“资源无法找到”

当我在创建uploadSession时删除文件夹路径时,代码工作正常

你知道我可能做错了什么吗?

代码语言:javascript
运行
复制
   // 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 );
EN

回答 3

Stack Overflow用户

发布于 2020-09-18 22:03:58

确保最大。WebApplication中的上载大小设置大于文件大小。根据上传位置和SharePoint版本的不同,大小可能小于50MB。在本地,可以在CentralAdmin->Application Management->Web Application xy->General Settings中进行设置

另请检查https://docs.microsoft.com/de-de/archive/blogs/bgeoffro/list-attachments-over-50mb-need-more-than-an-increase-in-maximum-upload-size

票数 0
EN

Stack Overflow用户

发布于 2020-10-13 22:49:34

您是否能够成功地将文件上载到文档库的根目录?请参阅下面的代码。

代码语言:javascript
运行
复制
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();
票数 0
EN

Stack Overflow用户

发布于 2021-04-27 21:38:48

它确实适用于Graph 3.1.4和Java,我花了一段时间才让它工作,但它上传的文件>4MB相当性能…

// itemPath类似于"/myFolder/DailyUpload/“

代码语言:javascript
运行
复制
  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);
    }
}

希望这对其他人有帮助

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63909760

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档