Skip to content

Commit

Permalink
Merge pull request #112 from DDD-Community/fix/111
Browse files Browse the repository at this point in the history
[Fix/111] kakao share upload image error
  • Loading branch information
hwanheejung authored Sep 6, 2024
2 parents 4d382e9 + c763680 commit 01ae53c
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/app/board/[boardId]/_hooks/useSnsShare.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use client'

import { useEffect, useState } from 'react'
import { isDevMode } from '@/lib/utils/env'
import { isIOS, isAndroid } from 'react-device-detect'
import { useSession } from 'next-auth/react'
import { useEffect } from 'react'
import { isAndroid, isIOS } from 'react-device-detect'

const useSnsShare = () => {
const { data: session, status } = useSession()
Expand All @@ -22,8 +22,6 @@ const useSnsShare = () => {
}
}, [])

const [imageUrl, setImageUrl] = useState('')

const shareToKakao = async (boardName: string) => {
const { Kakao, location } = window
if (Kakao === undefined) {
Expand All @@ -44,11 +42,20 @@ const useSnsShare = () => {
}

try {
// 이미지 파일을 Blob으로 처리하여 File 객체 생성
const response = await fetch(OPTIONS.localImage)
const blob = await response.blob()
const file = new File([blob], 'opengraph-image-v2.png', {
type: 'image/png',
})

// upload image (로컬 사진은 사용할 수 없으므로 서버에 업로드 후 사용)
const res = await Kakao.Share.uploadImage({
file: OPTIONS.localImage,
const uploadRes = await Kakao.Share.uploadImage({
file: [file],
})
setImageUrl(res.infos.original.url)

const imageUrl = uploadRes.infos.original.url

Kakao.Share.sendDefault({
objectType: 'feed',
content: {
Expand Down

0 comments on commit 01ae53c

Please sign in to comment.