由于OneDrive上传API发生未知错误,导致OneDriveSDK失败

时间:2019-08-29 23:56:20

标签: javascript azure onedrive

我必须做一个页面才能上传大文件。

我正在尝试使用OneDrive API直接上传到OneDrive,并且服务器没有问题。

我的HTML文件:

    <head>
        <script type="text/javascript" src="https://js.live.net/v7.2/OneDrive.js"></script>
    </head>
    <body>
        <script type="text/javascript">
            function launchSaveToOneDrive(){
                console.log('ok');
                let odOptions = {
                    clientId: "xxx",
                    action: "save",
                    sourceInputElementId: "fileUploadControl",
                    sourceUri: "",
                    fileName: "teste.txt",
                    openInNewWindow: false,
                    advanced: {
                        redirectUri: "http://localhost:8000/teste"
                    },
                    success: function(files) { console.log('ok'); },
                    progress: function(percent) { console.log(percent); },
                    cancel: function() { /* cancel handler */ },
                    error: function(error) { console.log(error); }
                };
            OneDrive.save(odOptions);
          }
        </script>

        <input id="fileUploadControl" name="fileUploadControl" type="file" />
        <button onclick="launchSaveToOneDrive()">Save to OneDrive</button>
    </body>

我已经配置了返回uri。

当我单击“保存”时,它将打开一个新窗口以使用Microsoft帐户登录。 当我插入电子邮件后,它将关闭并在控制台上返回错误。

[OneDriveSDK] Failed due to unknown error:  [1]Error at new e (https://js.live.net/v7.2/OneDrive.js:4:32389) at https://js.live.net/v7.2/OneDrive.js:4:19217

(index):22 Error
    at new e (OneDrive.js:4)
    at OneDrive.js:4

我什么都没找到。

1 个答案:

答案 0 :(得分:1)

它对我来说使用相同的代码。这是带有上载的网络通话的屏幕截图:

enter image description here

这是我使用的代码,我确保它具有上传文件的正确权限。

function launchSaveToOneDrive(){
                console.log('ok');
                let odOptions = {
                    clientId: "XXXXXX-b802-4c4d-b6ae-a1675f9be514",                    
                    action: "save",
                    sourceInputElementId: "fileUploadControl",
                    sourceUri: "",
                    fileName: "Screenshot.png",
                    openInNewWindow: false,
                    advanced: {
                        redirectUri: "http://localhost:9999/index.html"
                    },
                    success: function(files) { console.log('ok'); },
                    progress: function(percent) { console.log(percent); },
                    cancel: function() { /* cancel handler */ },
                    error: function(error) { console.log(error); }
                };
            OneDrive.save(odOptions);
          }

这是回调设置:

enter image description here

这是api权限:

enter image description here

请确保您对应用程序具有正确的访问权限,并检查ODOption中的文件名是否正确。让我知道是否需要代码存储库,将其共享。