使用JS FileReader API读取Sharepoint文档库文件

时间:2018-07-11 22:10:20

标签: javascript sharepoint filereader sharepoint-online spservices

我看到这个问题的其他版本没有提供Javascript解决方案。有人可以为此创建一个吗?我把头撞在墙上,试图使它起作用。

因此,我的总体工作范围是复制文件,然后将其放入另一个文档库中,但是我在读取文件时遇到了麻烦。到目前为止,这是我最好的尝试...

init(window:)

1 个答案:

答案 0 :(得分:0)

使用xhr通过以下功能将文档读入字节数组:

function ReadDocument(documentUrl) {
        try {
            if (documentUrl) {
                    var xhr = new XMLHttpRequest();
                    xhr.onreadystatechange = function (data) {
                        if (this.readyState == 4 && this.status == 200) {
							var fileData = this.response;
                        }
                    }
                    xhr.open('GET', documentUrl, true);
                    xhr.responseType = 'blob';
                    xhr.send();
            }
        } catch (e) {
            console.log(e);
        }
    }

我也不建议使用SPService库,因为它是第三方库,并且该库中的大多数功能都可以在REST api中获得。