Commit a842861c by Haohao Jiang

fix: rename upload method name

parent 8781869c
BOBCAT_HOST=xxxxxxxxx
BOBCAT_USER_COOKIE=xxxxxxxxx
DESIGN_TEAM_CHANNEL_ID=xxxxxxxxx
GOOGLE_SERVICE_ACCOUNT_KEY_FILE=xxxxxxxxx
GOOGLE_SHEET_AI_ID=xxxxxxxxx
GOOGLE_SHEET_ID=xxxxxxxxx
GSHEET_AI_DELAY_MS=xxxxxxxxx
SLACK_WEBHOOK=xxxxxxxxx
# AWS S3 Configuration
AWS_REGION=ap-northeast-1
AWS_ACCESS_KEY_ID=your_access_key_id
AWS_SECRET_ACCESS_KEY=your_secret_key
AWS_S3_BUCKET_NAME=your_bucket_name
\ No newline at end of file
......@@ -31,9 +31,9 @@ AWS_S3_BUCKET_NAME=your_bucket_name
### 使用示例
```typescript
import { uploadFileFromEnv } from './src/clients/s3';
import { uploadToS3 } from './src/clients/s3';
const key = await uploadFileFromEnv(
const key = await uploadToS3(
'/path/to/local/file.pdf',
'uploads/file.pdf',
{ contentType: 'application/pdf', acl: 'private' }
......
......@@ -3,10 +3,10 @@
*
* 使用示例:
* ```typescript
* import { uploadFileFromEnv } from './clients/s3';
* import { uploadToS3 } from './clients/s3';
*
* // 上传文件(自动读取环境变量)
* const key = await uploadFileFromEnv(
* const key = await uploadToS3(
* '/path/to/file.pdf',
* 'uploads/file.pdf',
* { contentType: 'application/pdf', acl: 'private' }
......@@ -15,8 +15,7 @@
*/
import { S3Client, PutObjectCommand } from '@aws-sdk/client-s3';
import { createReadStream, statSync } from 'fs';
import { basename } from 'path';
import { readFileSync } from 'fs';
/**
* S3 Configuration
......@@ -64,14 +63,12 @@ export async function uploadFile(
options?: UploadOptions
): Promise<string> {
const client = createS3Client(config);
const fileStream = createReadStream(filePath);
const fileStat = statSync(filePath);
const fileContent = readFileSync(filePath);
const uploadParams: any = {
Bucket: config.bucketName,
Key: key,
Body: fileStream,
ContentLength: fileStat.size,
Body: fileContent,
};
if (options?.contentType) {
......@@ -99,7 +96,7 @@ export async function uploadFile(
* @param options Upload options
* @returns The S3 object key
*/
export async function uploadFileFromEnv(
export async function uploadToS3(
filePath: string,
key: string,
options?: UploadOptions
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment