简体   繁体   English

如何使用Office365 REST API将OneDrive文件下载到Ruby变量中?

[英]How can I download a OneDrive file with Office365 REST API into a Ruby variable?

I'm building a Ruby on Rails app, and I'd like to integrate some Office365 features. 我正在构建Ruby on Rails应用程序,并且希望集成一些Office365功能。

For instance : I would like to download a file from OneDrive and then attach it to an Email in order to send it via Outlook rest API. 例如:我想从OneDrive下载文件,然后将其附加到电子邮件,以便通过Outlook rest API发送文件。

I found this get Item content OneDrive REST API but I dont understand how to use it. 我发现此获取项目内容OneDrive REST API,但我不知道如何使用它。

I understand that I have to send a GET request (formated as explained in msdn.microsoft.com) with Rails, which will then provide me a " a pre-authenticated download URL " to download the file. 我知道我必须使用Rails发送GET请求(格式如msdn.microsoft.com中所述),然后该Rails将为我提供一个“ 预先认证的下载URL ”以下载文件。

Then I will have to send a second GET request with this a pre-authenticated download URL to start the download, but I don't understand how to deal with the Response in order to save the file into a variable. 然后,我将不得不发送带有此预认证下载URL的第二个GET请求才能开始下载,但是我不知道如何处理Response以便将文件保存到变量中。

How can I retrieve the file into a variable of my Ruby on Rails App, so that I can attach it to an Email with an Outlook REST API to send it from my own Rail controller ? 如何将文件检索到Ruby on Rails应用程序的变量中,以便可以使用Outlook REST API将其附加到电子邮件,以从我自己的Rail控制器发送该文件?

Also this workflow is really not optimized in term of Bandwidth and Processing (3 REST API request + 1 download + 1 upload), it will work. 同样,此工作流实际上并未在带宽和处理方面进行优化(3个REST API请求+ 1个下载+ 1个上传),它将起作用。

However if it exist a single REST API that direclty attach a OneDrive file to an email to send it, that would ease a lot my life, save energy, save money from Microsoft datacenter, and spare the planet ecology . 但是,如果存在一个单独的REST API,并且不愿意将OneDrive文件附加到电子邮件中发送该文件,那将大大减轻我的生活,节省能源,从Microsoft数据中心节省资金,并节省地球生态

Any tutorial, examples, or more explanatory doc would be much appreciated. 任何教程,示例或更具说明性的文档,将不胜感激。

--- EDIT --- Adding link to the email is not wished as the email may have to be send to someone outside of Office365 users, and public link are a security issue for confidential documents. ---编辑---不希望在电子邮件中添加链接,因为可能必须将电子邮件发送给Office365用户之外的人,并且公共链接是机密文档的安全问题。

Any help is welcome. 欢迎任何帮助。

There isn't a single REST API call you can make currently to do what you want, although being able to easily attach a file from OneDrive to a new email message is a great scenario for Microsoft Graph API, it just isn't supported right now. 尽管可以轻松地将OneDrive中的文件附加到新电子邮件中,这对Microsoft Graph API来说是一个很好的方案,但是您目前无法进行任何REST API调用来完成所需的工作现在。

If you want to attach the file, you need to do as you mentioned, download the contents of the file, and then upload it again as an attachment to the message. 如果要附加文件,则需要按照上述说明进行操作,下载文件的内容,然后再次将其作为邮件的附件上载。

However, I'd recommend sending a link to the file instead, even though you mentioned you don't want to do that. 但是,即使您提到您不想这样做,我还是建议您发送指向该文件的链接。 OneDrive for Business now supports "company shareable links" which are scoped to just the user's organization instead of being available totally anonymously. 现在,OneDrive for Business支持“公司共享链接”,其范围仅限于用户的组织,而不是完全匿名使用。

Something else to consider: The security concerns of sending an anonymous link aren't that different than sending an attached file. 需要考虑的其他事项:发送匿名链接的安全性与发送附件无关。 In fact, the anonymous link can be more secure, because access to the file can be monitored and revoked in the future (unlike the attachment, which will always be out there). 实际上,匿名链接可以更安全,因为将来可以监视和撤消对文件的访问(与附件一模一样,附件始终都在那里)。

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

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