【问题标题】:How to upload pdf file to Sharepoint site using MicrosoftGraph如何使用 MicrosoftGraph 将 pdf 文件上传到 Sharepoint 站点
【发布时间】:2020-05-13 14:22:22
【问题描述】:

我正在尝试使用 Microsoft Graph API 将存储在移动设备上的 pdf 传输到 Sharepoint 站点。该文件被读取为 base64 字符串,并且该字符串被设置为站点上文件的内容。

我已成功传输纯文本文件,但无法使用 pdf 传输。好像我只是在创建一个带有 .pdf 扩展名的纯文本文件(可以将扩展名更改为 .txt,该文件只包含原始文件的字符串版本)。

关于如何指定正在传输的字符串是文件的编码版本而不仅仅是纯文本的任何想法?我假设在上传图像或任何非.txt 文件时就是这种情况,因此任何相关建议都会有所帮助。

graphClient.api('/sites/{site-id}/drives/{drive-id}/root:/UploadedFile.pdf:/content')
            .header("content-type", "application/pdf")
            .put(fileContent)
            .then((response) => {
                console.log(response);
            });

【问题讨论】:

    标签: pdf file-upload upload microsoft-graph-api microsoft-graph-files


    【解决方案1】:

    我解决了这个问题。我使用 Buffer 将 base64 字符串转换为二进制。

    const fileContentAsBinary = Buffer.from(fileContent, "base64");
    graphClient.api('/sites/{site-id}/drives/{drive-id}/root:/UploadedFile.pdf:/content')
                .header("content-type", "application/pdf")
                .put(fileContentAsBinary)
                .then((response) => {
                    console.log(response);
                });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-08
      • 1970-01-01
      • 1970-01-01
      • 2021-08-29
      • 1970-01-01
      相关资源
      最近更新 更多