使用 Azure 逻辑应用访问和管理 OneDrive 连接器中的文件Access and manage files in OneDrive connector by using Azure Logic Apps

通过使用 Azure 逻辑应用OneDrive 连接器,可以创建自动化任务和工作流来管理文件,包括上传、获取、删除文件等。By using Azure Logic Apps and the OneDrive connector, you can create automated tasks and workflows to manage your files, including upload, get, delete files, and more. 使用 OneDrive,可以执行以下任务:With OneDrive, you can perform these tasks:

  • 通过在 OneDrive 中存储文件生成工作流,或更新 OneDrive 中的现有文件。Build your workflow by storing files in OneDrive, or update existing files in OneDrive.
  • 在 OneDrive 内创建或更新文件时,使用触发器启动工作流。Use triggers to start your workflow when a file is created or updated within your OneDrive.
  • 使用创建文件、删除文件等操作。Use actions to create a file, delete a file, and more. 例如,收到带有附件的新 Office 365 电子邮件时(触发器),在 OneDrive 中新建文件(操作)。For example, when a new Office 365 email is received with an attachment (a trigger), create a new file in OneDrive (an action).

本文演示如何在逻辑应用中使用 OneDrive 连接器,还列出了触发器和操作。This article shows you how to use the OneDrive connector in a logic app, and also lists the triggers and actions.

若要了解有关逻辑应用的详细信息,请参阅什么是逻辑应用创建逻辑应用To learn more about Logic Apps, see What are logic apps and create a logic app.

连接到 OneDriveConnect to OneDrive

在逻辑应用能够访问任何服务前,需要先创建到该服务的连接Before your logic app can access any service, you first create a connection to the service. 连接提供逻辑应用和其他服务之间的连接性。A connection provides connectivity between a logic app and another service. 例如,若要连接到 OneDrive,首先需要 OneDrive 连接For example, to connect to OneDrive, you first need a OneDrive connection. 若要创建连接,请输入通常用于访问要连接到的服务的凭据。To create a connection, enter the credentials you normally use to access the service you wish to connect to. 因此,在 OneDrive 中,将凭据输入到 OneDrive 帐户以创建连接。So, with OneDrive, enter the credentials to your OneDrive account to create the connection.

创建连接Create the connection

先决条件Prerequisites

可以在逻辑应用中使用 OneDrive 帐户之前,请先授权该逻辑应用可以连接到 OneDrive 帐户。Before you can use your OneDrive account in a logic app, authorize the logic app to connect to your OneDrive account. 可以在 Azure 门户中的逻辑应用内轻松地执行此操作。You can do this easily within your logic app on the Azure portal.

按照以下步骤操作,即可授权逻辑应用连接到 OneDrive 帐户:Authorize your logic app to connect to your OneDrive account using the following steps:

  1. 创建逻辑应用。Create a logic app. 在逻辑应用设计器的下拉列表中选择“显示 Microsoft 托管的 API”,并在搜索框中输入“onedrive”。In the Logic Apps designer, select Show Microsoft managed APIs in the drop down list, and then enter "onedrive" in the search box. 选择其中一个触发器或操作:Select one of the triggers or actions:

  2. 如果以前尚未创建任何与 OneDrive 的连接,系统会提示使用 OneDrive 凭据进行登录:If you haven't previously created any connections to OneDrive, you are prompted to sign in using your OneDrive credentials:

  3. 选择“登录”,并输入用户名和密码。Select Sign in, and enter your user name and password. 选择“登录”:Select Sign in:

    这些凭据将用于授权逻辑应用连接到你的 OneDrive 帐户,并访问该帐户中的数据。These credentials are used to authorize your logic app to connect to, and access the data in your OneDrive account.

  4. 选择“是”即可授权逻辑应用使用 OneDrive 帐户:Select Yes to authorize the logic app to use your OneDrive account:

  5. 请注意,连接已创建。Notice the connection has been created. 现在,继续在逻辑应用中执行其他步骤:Now, proceed with the other steps in your logic app:

使用触发器Use a trigger

触发器是用于启动在逻辑应用中定义的工作流的事件。A trigger is an event that can be used to start the workflow defined in a logic app. 触发器以希望的间隔和频率“轮询”服务。Triggers "poll" the service at an interval and frequency that you want. 了解有关触发器的详细信息Learn more about triggers.

  1. 在逻辑应用设计器中,键入 onedrive 以获取触发器列表:In the Logic App Designer, type onedrive to get a list of the triggers:

  2. 选择“修改文件时” 。Select When a file is modified. 如果连接已存在,选择“显示选取器”按钮选择文件夹。If a connection already exists, then select the Show Picker button to select a folder.

    如果提示登录,则输入登录详细信息以创建连接。If you are prompted to sign in, then enter the sign in details to create the connection. 本文中的创建连接列出了相关步骤。Create the connection in this article lists the steps.

    在此示例中,逻辑应用在更新所选文件夹中的文件时运行。In this example, the logic app runs when a file in the folder you choose is updated. 要查看此触发器的结果,请添加另一个向你发送电子邮件的操作。To see the results of this trigger, add another action that sends you an email. 例如,添加在更新文件时向你发送电子邮件的 Office 365 Outlook“发送电子邮件”操作 。For example, add the Office 365 Outlook Send an email action that emails you when a file is updated.

  3. 选择“编辑” 按钮并设置“频率” 和“间隔” 值。Select the Edit button and set the Frequency and Interval values. 例如,如果希望触发器每 15 分钟轮询一次,将“频率” 设置为“分钟” ,将“间隔” 设置为“15” 。For example, if you want the trigger to poll every 15 minutes, then set the Frequency to Minute, and set the Interval to 15.

  4. 保存更改(工具栏的左上角)。Save your changes (top left corner of the toolbar). 逻辑应用将保存,并且可能自动启用。Your logic app is saved and may be automatically enabled.

使用操作Use an action

操作是指在逻辑应用中定义的工作流所执行的操作。An action is an operation carried out by the workflow defined in a logic app. 了解有关操作的详细信息Learn more about actions.

  1. 选择加号。Select the plus sign. 可看到多个选项:“添加操作” 、“添加条件” 或“更多” 选项之一。You see several choices: Add an action, Add a condition, or one of the More options.

  2. 选择“添加操作” 。Choose Add an action.

  3. 在搜索框中,键入 onedrive 以获取所有可用操作的列表。In the search box, type onedrive to get a list of all the available actions.

  4. 在我们的示例中,选择“OneDrive - 创建文件” 。In our example, choose OneDrive - Create file. 如果连接已存在,选择“文件夹路径” 放入文件、输入“文件名” ,并选择所需的“文件内容” :If a connection already exists, then select the Folder Path to put the file, enter the File Name, and choose the File Content you want:

    如果系统提示你提供连接信息,请输入详细信息以创建连接,如本主题中所述。If you are prompted for the connection information, enter the details to create the connection as described in this topic.

    在此示例中,你将在 OneDrive 文件夹中创建一个新文件。In this example, you create a new file in a OneDrive folder. 可使用来自其他触发器的输出创建 OneDrive 文件。You can use output from another trigger to create the OneDrive file. 例如,添加 Office 365 Outlook“新电子邮件到达时” 触发器。For example, add the Office 365 Outlook When a new email arrives trigger. 然后添加可在 ForEach 内使用“附件”和“内容类型”字段的 OneDrive“创建文件”操作,在 OneDrive 中新建文件 。Then add the OneDrive Create file action that uses the Attachments and Content-Type fields within a ForEach to create the new file in OneDrive.

  5. 保存更改(工具栏的左上角)。Save your changes (top left corner of the toolbar). 逻辑应用将保存,并且可能自动启用。Your logic app is saved and may be automatically enabled.

特定于连接器的详细信息Connector-specific details

连接器详细信息中查看在 Swagger 中定义的触发器和操作,并查看限制。View any triggers and actions defined in the swagger, and also see any limits in the connector details.

后续步骤Next steps