简体   繁体   中英

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). When a channel is deleted, my bot saves all messages and creates html file with messages that were in that channel. 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. The below variable attachment holds the html file/string to be uploaded.

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

You can use Node SSH to log into your server via SSH and upload the file.

Rest API

Host a simple and secure Rest API in the server to write the HTML file and call it from your main application.

AWS S3

If you are using AWS , Create an S3 Bucket , make it publicly readable and enable static web hosting . Now you can put your HTML files to your S3 Bucket using AWS-SDK and access them via S3 Bucket Url .

If you are using some other cloud platform like Azure / GCP, Checkout their own storage service.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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