질문&답변
여러 사진 중 일부 사진의 허용 사이즈 초과로 실패한 경우에 대해
반영 코드 도움되시는분 있으실까 첨부합니다 export async function createPostWithImages({ content, images, userId, }: { content: string; images: File[]; userId: string; }) { // 1. 새로운 포스트 생성 const post = await createPost(content); if (images.length === 0) return post; const uploadedFilePaths: string[] = []; try { // 2. 이미지 업로드 const imageUrls = await Promise.all( images.map((image) => { const fileExtension = image.name.split(".").pop() || "webp"; const fileName = `${Date.now()}-${crypto.randomUUID()}.${fileExtension}`; const filePath = `${userId}/${post.id}/${fileName}`; uploadedFilePaths.push(filePath); return uploadImage({ file: image, filePath, }); }), ); // 3. 포스트 테이블 업데이트 const updatedPost = await updatePost({ id: post.id, image_urls: imageUrls, }); return updatedPost; } catch (error) { await Promise.all([ deletePost(post.id), uploadedFilePaths.length > 0 ? deleteImages(uploadedFilePaths) : Promise.resolve(), ]); throw error; } }
- 좋아요수
- 3
- 댓글수
- 2
- 조회수
- 144





