【问题标题】:Uploading a file to the teams onedrive from custom teams app tab从自定义团队应用程序选项卡将文件上传到团队 onedrive
【发布时间】:2021-06-14 19:05:51
【问题描述】:

我试图在我的自定义团队应用程序中获取选项卡以从 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 完全陌生。

【问题讨论】:

  • HI @7BitAscii,是的,您可以使用 API 自动将文件上传到一个驱动器,请通过 docs 供您参考。
  • @Ravindra-MSFT 来自我正在阅读的内容,专门针对已经在 onedrive 或共享点上的项目。我的目标是将与任何 Microsoft 产品无关的新文件上传到我团队在 MS 团队中的 onedrive。这也可能吗?还是我的文件已经需要放在一个驱动器上?

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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-22
    • 1970-01-01
    • 2019-03-11
    • 2019-10-19
    • 2013-01-27
    • 2022-06-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多