Help passing uploaded image (blob) into server action #135
-
I have this code: onChange={async (e: React.ChangeEvent<HTMLInputElement>) => {
e.stopPropagation()
if (e.target.files && e.target.files[0]) {
const uploadedFile = e.target.files[0]
local.uploadedImage.set(uploadedFile)
await describeImageAction({
imageBlob: e.target.files[0],
huggingFaceToken:
"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",
})
}
}}
```
Code for it here: https://github.com/kuskusapp/kuskus/blob/main/components/AddPostModal.tsx#L125
Action here:
```js
const describeImageSchema = z.object({
imageBlob: z.any(),
huggingFaceToken: z.string(),
})
export const describeImageAction = actionClient
.schema(describeImageSchema)
.action(async ({ parsedInput: { imageBlob, huggingFaceToken } }) => {
console.log("wtf try run it")
const session = auth.getSession()
console.log(session, "sesh")
if (session) {
try {
let imageDescription = await describeImage(imageBlob, huggingFaceToken)
console.log(imageDescription)
return imageDescription
} catch (err) {
return { failure: "Error describing image:", errorDetails: err.message }
}
}
})
```
Code: https://github.com/kuskusapp/kuskus/blob/main/app/actions.ts#L52
Currently it just silently breaks. No logs. |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 6 replies
-
getting this now trying to do: |
Beta Was this translation helpful? Give feedback.
-
ok now getting an issue my input: calls this action: it fails with bad request for some reason, i pass then try pass it to endpoint (https://huggingface.co/nlpconnect/vit-gpt2-image-captioning?inference_api=true) which accepts a but for some reason |
Beta Was this translation helpful? Give feedback.
-
https://next-safe-action.dev/docs/usage-with-forms trying to make it work with forms, maybe that works |
Beta Was this translation helpful? Give feedback.
-
my latest code looks like this, trying to make it work pushed it to https://github.com/kuskusapp/kuskus |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
from https://discord.com/channels/974519864045756446/1037561178286739466/1242099532523634770 |
Beta Was this translation helpful? Give feedback.
-
pushed code in: https://github.com/kuskusapp/kuskus/blob/main/app/actions.ts super confused, open to call to resolve this if possible 🙏 |
Beta Was this translation helpful? Give feedback.
-
ok thank you @TheEdoRan const resp = await describeImageAction({
imageAsBase64: base64Image,
})
console.log(resp, "response from action")
console.log(resp.serverError, "server error") this helped me get the error so happy |
Beta Was this translation helpful? Give feedback.
This is the right URL: https://next.next-safe-action.dev/docs/safe-action-client/initialization-options#handlereturnedservererror
next-safe-action catches errors that occur during execution, on the server. If that happens, the
serverError
property of the action result object gets set.If you want to rethrow all server errors, you can easily achieve that behavior by doing that inside
handleReturnedServerError
function.