简体   繁体   English

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

[英]Uploading a file to the teams onedrive from custom teams app tab

Im trying to get the tab in my custom teams app to fetch a list of files from a URL, and want to upload one of those files to the corresponding teams onedrive afterwards.我试图在我的自定义团队应用程序中获取选项卡以从 URL 获取文件列表,然后希望将其中一个文件上传到相应的团队 onedrive。 I have somewhat been able to do the first part (fetching a list of files) but im completely lost on how to use Graph API or an incoming webhook, or whatever solution available to upload a file to the teams onedrive without having to manually upload it.我已经能够完成第一部分(获取文件列表),但我完全不知道如何使用 Graph API 或传入的 webhook,或者任何可用于将文件上传到团队 onedrive 的解决方案,而无需手动上传. How do i get my app to upload the file to teams from a URL?如何让我的应用程序将文件从 URL 上传到团队?

My code as it is right now:我现在的代码:

// 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;

I somehow need to pick an item off that list, and then use the graph API or another solution to upload that file to the teams onedrive, how do i do that?我不知何故需要从该列表中选择一个项目,然后使用图表 API 或其他解决方案将该文件上传到团队 onedrive,我该怎么做?

Any help greatly appreciated, On a side note.非常感谢任何帮助,附带说明。 im completely new to javascript.我对 javascript 完全陌生。

You can upload files from URLs, Drive using Graph API.您可以使用 Graph API 从 URL 上传文件。 You can through this documentation which provides API for uploading files.您可以通过此文档提供 API 用于上传文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM