简体   繁体   English

使用 nodejs 以编程方式将 html 文件上传到 web 服务器

[英]Programatically upload html files to a web server with nodejs

I have a discord js bot with tickets system (A system where users can create private channel and ask staff for help).我有一个带有票务系统的 discord js 机器人(用户可以创建私人频道并向工作人员寻求帮助的系统)。 When a channel is deleted, my bot saves all messages and creates html file with messages that were in that channel.删除频道后,我的机器人会保存所有消息并创建 html 文件,其中包含该频道中的消息。 I want to upload that file to a web server so users can review it without having to download it, but I am unsure how to do it.我想将该文件上传到 web 服务器,以便用户无需下载即可查看它,但我不确定如何操作。 The below variable attachment holds the html file/string to be uploaded.下面的变量attachment包含要上传的 html 文件/字符串。

const attachment = await discordTranscripts.createTranscript(channel, {
      limit: -1, // Max amount of messages to fetch.
      returnType: 'attachment', // Valid options: 'buffer' | 'string' | 'attachment' Default: 'attachment'
      fileName: fileName, // Only valid with returnBuffer false. Name of attachment. 
      minify: true // Minify the result? Uses html-minifier
   });

This is quite opinion-based question.这是一个相当基于意见的问题。 There are a lot of ways to do it.有很多方法可以做到这一点。

SSH SSH

You can use Node SSH to log into your server via SSH and upload the file.您可以使用节点 SSH通过SSH登录您的服务器并上传文件。

Rest API Rest API

Host a simple and secure Rest API in the server to write the HTML file and call it from your main application.在服务器中托管一个简单且安全的Rest API以编写HTML 文件并从您的主应用程序中调用它。

AWS S3 AWS S3

If you are using AWS , Create an S3 Bucket , make it publicly readable and enable static web hosting .如果您使用AWS ,请创建一个S3 存储桶,使其公开可读并启用static web 托管 Now you can put your HTML files to your S3 Bucket using AWS-SDK and access them via S3 Bucket Url .现在,您可以使用AWS-SDKHTML 文件放入您的S3 存储桶,并通过S3 存储桶 Url访问它们。

If you are using some other cloud platform like Azure / GCP, Checkout their own storage service.如果您使用的是其他云平台,例如 Azure / GCP,请查看他们自己的存储服务。

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

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