Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
cf3eb3b7
authored
Jun 14, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: upload img
parent
7c52cec0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
6 deletions
+17
-6
client/src/pages/api/system/uploadImage.ts
+17
-6
No files found.
client/src/pages/api/system/uploadImage.ts
View file @
cf3eb3b7
...
@@ -3,20 +3,20 @@ import { jsonRes } from '@/service/response';
...
@@ -3,20 +3,20 @@ import { jsonRes } from '@/service/response';
import
{
connectToDatabase
,
Image
}
from
'@/service/mongo'
;
import
{
connectToDatabase
,
Image
}
from
'@/service/mongo'
;
import
{
authUser
}
from
'@/service/utils/auth'
;
import
{
authUser
}
from
'@/service/utils/auth'
;
// get the models available to the system
type
Props
=
{
base64Img
:
string
};
export
default
async
function
handler
(
req
:
NextApiRequest
,
res
:
NextApiResponse
)
{
export
default
async
function
handler
(
req
:
NextApiRequest
,
res
:
NextApiResponse
)
{
try
{
try
{
await
connectToDatabase
();
await
connectToDatabase
();
const
{
userId
}
=
await
authUser
({
req
,
authToken
:
true
});
const
{
userId
}
=
await
authUser
({
req
,
authToken
:
true
});
const
{
base64Img
}
=
req
.
body
;
const
{
base64Img
}
=
req
.
body
as
Props
;
const
base64Data
=
base64Img
.
split
(
','
)[
1
];
const
{
_id
}
=
await
Image
.
create
({
const
data
=
await
uploadImg
({
userId
,
userId
,
b
inary
:
Buffer
.
from
(
base64Data
,
'base64'
)
b
ase64Img
});
});
jsonRes
(
res
,
{
data
:
`/api/system/img/
${
_id
}
`
});
jsonRes
(
res
,
{
data
});
}
catch
(
error
)
{
}
catch
(
error
)
{
jsonRes
(
res
,
{
jsonRes
(
res
,
{
code
:
500
,
code
:
500
,
...
@@ -24,3 +24,14 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
...
@@ -24,3 +24,14 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
});
});
}
}
}
}
export
async
function
uploadImg
({
base64Img
,
userId
}:
Props
&
{
userId
:
string
})
{
const
base64Data
=
base64Img
.
split
(
','
)[
1
];
const
{
_id
}
=
await
Image
.
create
({
userId
,
binary
:
Buffer
.
from
(
base64Data
,
'base64'
)
});
return
`/api/system/img/
${
_id
}
`
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment