mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-11-13 12:43:42 +08:00
feat: support other type file upload
This commit is contained in:
@@ -4,6 +4,7 @@ import { auth } from "@/app/api/auth";
|
||||
import LocalFileStorage from "@/app/utils/local_file_storage";
|
||||
import { getServerSideConfig } from "@/app/config/server";
|
||||
import S3FileStorage from "@/app/utils/s3_file_storage";
|
||||
import path from "path";
|
||||
|
||||
async function handle(req: NextRequest) {
|
||||
if (req.method === "OPTIONS") {
|
||||
@@ -19,20 +20,21 @@ async function handle(req: NextRequest) {
|
||||
|
||||
try {
|
||||
const formData = await req.formData();
|
||||
const image = formData.get("file") as File;
|
||||
const file = formData.get("file") as File;
|
||||
const originalFileName = file?.name;
|
||||
|
||||
const imageReader = image.stream().getReader();
|
||||
const imageData: number[] = [];
|
||||
const fileReader = file.stream().getReader();
|
||||
const fileData: number[] = [];
|
||||
|
||||
while (true) {
|
||||
const { done, value } = await imageReader.read();
|
||||
const { done, value } = await fileReader.read();
|
||||
if (done) break;
|
||||
imageData.push(...value);
|
||||
fileData.push(...value);
|
||||
}
|
||||
|
||||
const buffer = Buffer.from(imageData);
|
||||
|
||||
var fileName = `${Date.now()}.png`;
|
||||
const buffer = Buffer.from(fileData);
|
||||
const fileType = path.extname(originalFileName).slice(1);
|
||||
var fileName = `${Date.now()}.${fileType}`;
|
||||
var filePath = "";
|
||||
const serverConfig = getServerSideConfig();
|
||||
if (serverConfig.isStoreFileToLocal) {
|
||||
|
||||
Reference in New Issue
Block a user