SharePoint Online:如何使用客户端JavaScript对象模型上传大文件? [英] SharePoint Online : How to upload large file using client side JavaScript object model?

查看:109
本文介绍了SharePoint Online:如何使用客户端JavaScript对象模型上传大文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我正在尝试使用客户端JavaScript对象模型上载SharePoint文档库中的文件,但它仅适用于最大1000 KB的较小文件.请在下面找到较小文件的工作代码块.

I am trying to upload file in SharePoint document library using client side JavaScript object model but its working only for smaller files up to 1000 KB. Please find below working code block for smaller files.

function uploadFile() {
    uploadAttachmentFilesId = '';
    var context = SP.ClientContext.get_current();
    var Web = context.get_web();
    var list = Web.get_lists().getByTitle(DocumentsLibraryName);

    var fileCreateInfo = new SP.FileCreationInformation();
    fileCreateInfo.set_url(file.filename);
    fileCreateInfo.set_overwrite(true);
    fileCreateInfo.set_content(new SP.Base64EncodedByteArray());

    // Read the binary contents of the base 64 data URL into a Uint8Array
    // Append the contents of this array to the SP.FileCreationInformation
    var arr = convertDataURIToBinary(file.data);
    for (var i = 0; i < arr.length; ++i) {
        fileCreateInfo.get_content().append(arr[i]);
    }

    // Upload the file to the root folder of the document library
    var newFile = list.get_rootFolder().get_files().add(fileCreateInfo);
    var listitem = newFile.get_listItemAllFields();
    listitem.update();
    context.load(newFile, 'ListItemAllFields');
    context.executeQueryAsync(onSuccess, onFailure);

    function onSuccess() {
        uploadAttachmentFilesId = newFile.get_listItemAllFields().get_id();
    }

    function onFailure(args) {
        // Error occurred
    }
}

任何人都可以通过代码帮助我上传最大5 MB的大文件吗?我可以使用REST api上传它,但我只需要使用客户端JavaScript对象模型即可实现.请帮忙.

Can any one please help me with the code to upload large files up to 5 MBs? I am able to upload it using REST api but i would need to achieve this using client side JavaScript object model only. Please help.

预先感谢您的帮助.

致谢.


推荐答案

希望以下帮助

https://docs.microsoft.com/zh-cn/sharepoint/dev/solution-guidance/upload-large-files-sample-app-for-sharepoint

https://docs.microsoft.com/en-us/sharepoint/dev/solution-guidance/upload-large-files-sample-app-for-sharepoint


这篇关于SharePoint Online:如何使用客户端JavaScript对象模型上传大文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆