服务器中的脚本在本地保存 [英] Script in server saving locally

查看:139
本文介绍了服务器中的脚本在本地保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个脚本,该脚本使用slack API解析AWS S3文件以查找字符串或样本.在测试过程中,我正在使用本地计算机和ngrok转发本地主机流量.

I wrote a script that is using slack API to parse AWS S3 files looking for strings or samples. As this is in testing, I'm using my local machine and ngrok to forward localhost traffic.

问题是生成的文件正在我的计算机中存储,一旦脚本准备好用于生产,这些文件就会存储在服务器中.

The thing is that the generated files are getting stores in my machine and will be stored in server once the script is ready for production.

理想情况下,我想避免用户需要从服务器获取文件.您认为可以直接存储在用户本地计算机中吗?

Ideally, I'd like to avoid users needing to grab files from server. Do you think it's possible to store directly in user local machine?

推荐答案

否. Slack不允许您通过Slack应用程序/API访问其用户的本地计算机.

No. Slack does not allow you to access the local machine of their users through a Slack app / API.

最简单的解决方案是在Slack消息中提供直接下载链接,例如通过链接"按钮.用户单击该文件后,系统会提示他将文件下载到其本地计算机上.

The easiest solution would be to offer a direct download link in a Slack message, e.g. via a Link button. Once the user clicks it he is prompted to download the file to his local machine.

这是我的一个应用程序中的一个示例:

Here is an example from one of my apps:

点击后,您会看到以下窗口:

And once you click it you get this window:

要启用通过浏览器的下载,您需要设置适当的标题并将文件内容发送到浏览器.

To enable downloading via browser you need to set appropriate headers and send the file contents to the browser.

一种方法是拥有一个用于实际下载的帮助程序脚本,并在链接按钮中包含指向该帮助程序脚本的链接(您可能还希望在链接中包括一些参数,这些参数定义了要下载哪个文件).

One approach is to have a helper script for the actual download and include a link to the helper script in the link button (you may also want to include some parameters in the link that defines what which file is downloaded).

然后,帮助程序脚本执行以下操作:

The helper script then does the following:

  1. 获取要下载的文件(例如PNG图片)
  2. 设置标题以允许通过浏览器下载
  3. 将文件发送到浏览器

以下是PHP中的示例:

Here is an example in PHP:

<?php
$filename = "demo.png";
$file = file_get_contents($filename);
header('Content-Disposition: attachment;filename=' . $filename);
header('Content-Type: image/png');
echo $file;
die();  

有关下载标题的更多信息,另请参见关于此的答案.

For more infos on download headers see also this answer on SO.

或者,您可以通过 file.upload 将文件上传到用户的Slack工作区. API方法.这样,用户无需下载任何内容,并且您可以在应用程序完成处理后从服务器中删除文件.

Alternatively you could upload the file to the user's Slack workspace via file.upload API method. That way the user does not need to download anything and and you can remove the file from your server after your app has finished processing.

这篇关于服务器中的脚本在本地保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆