从自定义团队应用程序选项卡将文件上传到团队 onedrive

时间:2021-06-14 19:05:51

标签: javascript reactjs microsoft-graph-api microsoft-teams microsoft-graph-teams

我正在尝试获取我的自定义团队应用程序中的选项卡,以从 URL 获取文件列表,然后希望将其中一个文件上传到相应的团队 onedrive。我在某种程度上能够完成第一部分(获取文件列表),但我完全不知道如何使用 Graph API 或传入的 webhook,或者任何可用于将文件上传到团队 onedrive 的解决方案,而无需手动上传它.如何让我的应用从 URL 将文件上传到团队?

我现在的代码:

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import React from 'react';
import './App.css';
import * as microsoftTeams from "@microsoft/teams-js";

class Tab extends React.Component {
  constructor(props){
    super(props)
    this.state = {
      context: {}
    }
  }

  componentDidMount(){
    microsoftTeams.getContext((context, error) => {
      this.setState({
        context: context
      });
    });
  }

  componentDidMount() {
    fetch("https://posts123.free.beeceptor.com")
      .then(res => res.json())
      .then(
        (result) => {
          this.setState({
            isLoaded: true,
            files: result.files
          });
        },
        (error) => {
          this.setState({
            isLoaded: true,
            error
          });
        }
      )
  }


  render() {   
    const { error, isLoaded, files } = this.state;
    if (error) {
      return <div>Error: {error.message}</div>;
    } else if (!isLoaded) {
      return <div>Loading...</div>;
    } else {
      return (
        <ul>
          {files.map(file => (
            <li key={file.id}>
              {file.name} {file.type}
            </li>
          ))}
        </ul>
      );
    }
  }
}
export default Tab;

我需要从该列表中选择一个项目,然后使用图形 API 或其他解决方案将该文件上传到团队 onedrive,我该怎么做?

非常感谢任何帮助!附带说明一下,我对 javascript 完全陌生。

1 个答案:

答案 0 :(得分:0)

您可以使用 Graph API 从 URL、Drive 上传文件。您可以通过此 documentation 提供上传文件的 API。

觉得有用请点赞。