Skip to content

Commit

Permalink
更新Blob数据使用方式
Browse files Browse the repository at this point in the history
  • Loading branch information
slince-zero committed May 9, 2024
1 parent 9dfe412 commit 841d34f
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/context/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,17 @@ export default function ImgContextProvider({
return result
}

function blobToDataURL(blob: any) {
return new Promise((resolve, reject) => {
const reader = new FileReader()
reader.onloadend = function () {
resolve(reader.result)
}
reader.onerror = reject
reader.readAsDataURL(blob)
})
}

// 生成AI图片
function handleGenerateAIImage() {
try {
Expand All @@ -258,8 +269,9 @@ export default function ImgContextProvider({
inputs: aiValue,
}
query(data).then((res) => {
const url = URL.createObjectURL(res)
setAiResult(url)
blobToDataURL(res).then((url) => {
setAiResult(url)
})
setLoadingAIImage(false)
})
} catch (e) {
Expand All @@ -278,8 +290,6 @@ export default function ImgContextProvider({
})
}



return (
<ImgContext.Provider
value={{
Expand Down

0 comments on commit 841d34f

Please sign in to comment.