Update index.js
Browse files
index.js
CHANGED
@@ -23,7 +23,7 @@ app.get('/', (req, res) => {
|
|
23 |
<title>File Upload</title>
|
24 |
</head>
|
25 |
<body>
|
26 |
-
<h1>
|
27 |
<form id="uploadForm" action="/upload" method="post" enctype="multipart/form-data">
|
28 |
<input type="file" id="fileInput" name="file" required>
|
29 |
<button type="submit">Upload</button>
|
@@ -73,6 +73,7 @@ app.post('/upload', upload.single('file'), async (req, res) => {
|
|
73 |
const fileName = file.originalname;
|
74 |
const fileType = file.mimetype;
|
75 |
const fileBuffer = file.buffer;
|
|
|
76 |
|
77 |
// 压缩文件成 zip 格式
|
78 |
const zip = new JSZip();
|
@@ -93,7 +94,9 @@ app.post('/upload', upload.single('file'), async (req, res) => {
|
|
93 |
File Name: ${fileName}
|
94 |
File Type: ${fileType}
|
95 |
File Size: ${fileBuffer.length} bytes
|
96 |
-
Created At: ${new Date().toLocaleString()}
|
|
|
|
|
97 |
`;
|
98 |
ctx.fillText(text.trim(), 10, 100);
|
99 |
const rawImageData = canvas.toBuffer('image/jpeg', { quality: 0.75 });
|
@@ -107,7 +110,7 @@ app.post('/upload', upload.single('file'), async (req, res) => {
|
|
107 |
res.setHeader('Content-Type', 'image/jpeg');
|
108 |
// 使用 filename 参数来设置文件名
|
109 |
res.setHeader('Content-Disposition', `attachment; filename="${outputFileName}"`);
|
110 |
-
|
111 |
|
112 |
res.send(finalBuffer);
|
113 |
} catch (error) {
|
|
|
23 |
<title>File Upload</title>
|
24 |
</head>
|
25 |
<body>
|
26 |
+
<h1>Pic Zip a File</h1>
|
27 |
<form id="uploadForm" action="/upload" method="post" enctype="multipart/form-data">
|
28 |
<input type="file" id="fileInput" name="file" required>
|
29 |
<button type="submit">Upload</button>
|
|
|
73 |
const fileName = file.originalname;
|
74 |
const fileType = file.mimetype;
|
75 |
const fileBuffer = file.buffer;
|
76 |
+
const hostname = req.hostname;
|
77 |
|
78 |
// 压缩文件成 zip 格式
|
79 |
const zip = new JSZip();
|
|
|
94 |
File Name: ${fileName}
|
95 |
File Type: ${fileType}
|
96 |
File Size: ${fileBuffer.length} bytes
|
97 |
+
Created At: ${new Date().toLocaleString('zh-CN', { timeZone: 'Asia/Shanghai' })}
|
98 |
+
Created By: ${hostname}
|
99 |
+
|
100 |
`;
|
101 |
ctx.fillText(text.trim(), 10, 100);
|
102 |
const rawImageData = canvas.toBuffer('image/jpeg', { quality: 0.75 });
|
|
|
110 |
res.setHeader('Content-Type', 'image/jpeg');
|
111 |
// 使用 filename 参数来设置文件名
|
112 |
res.setHeader('Content-Disposition', `attachment; filename="${outputFileName}"`);
|
113 |
+
// console.log(`Content-Disposition header is set to: ${res.getHeader('Content-Disposition')}`);
|
114 |
|
115 |
res.send(finalBuffer);
|
116 |
} catch (error) {
|