File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 1+ import { z } from "zod" ;
2+ import { handleActionException } from "./RepositoryException" ;
3+ import { PutObjectCommand } from "@aws-sdk/client-s3" ;
4+ import { env } from "@/env" ;
5+ import { s3Client } from "../s3.client" ;
6+
7+ const schema = z . object ( {
8+ url : z . string ( ) . url ( ) ,
9+ key : z . string ( ) ,
10+ } ) ;
11+
12+ export const uploadByUrl = async ( _input : z . infer < typeof schema > ) => {
13+ try {
14+ const input = await schema . parseAsync ( _input ) ;
15+ const api = await fetch ( input . url ) ;
16+ const body = await api . bytes ( ) ;
17+ const command = new PutObjectCommand ( {
18+ Bucket : env . S3_BUCKET ,
19+ Key : input . key ,
20+ ContentType : "image/jpeg" ,
21+ Body : body ,
22+ } ) ;
23+ await s3Client . send ( command ) ;
24+ } catch ( error ) {
25+ return handleActionException ( error ) ;
26+ }
27+ } ;
You can’t perform that action at this time.
0 commit comments