#Astro action function not uploading my file to Google Cloud Storage

19 messages · Page 1 of 1 (latest)

glass pawn
#

When I click the Submit button it ought to trigger the googleCloudStorage.uploadVideo function but i get back a result of undefined. I don't know why ?

main granite
#

Does it ever try to upload?

glass pawn
#

Nothing logs to the terminal even though I have a console.log there

main granite
#

So what happens when try to upload a file? Anything?

glass pawn
#

I get an okay o nthe network

#

but the action didn't really run

#

at least that's what it seems it does

#

but nothing

main granite
#

Are you SSR the page?

glass pawn
#

Unless I am missing a configuration for the nodejs adapter. as part of the setup for SSR

// @ts-check
import { defineConfig } from 'astro/config';

import react from '@astrojs/react';

import tailwindcss from '@tailwindcss/vite';

import node from '@astrojs/node';

// https://astro.build/config
export default defineConfig({
  integrations: [react()],

  vite: {
    plugins: [tailwindcss()]
  },

  adapter: node({
    mode: 'standalone'
  })

});
main granite
#

Set your output to server if you wanna do full SSR. Otherwise you can add the export const prerender at the top.

glass pawn
#

I see that seems to make a difference I am getting some output in my terminal from the console.log

main granite
#

Okay. So it’s not liking that file upload. Well at least it’s progress

glass pawn
#

It JUST WORKED. I fixed it. Thanks brother.
It wasn't liking the file upload because the name attribute on the input html element was not the same with the keys in the input z.object. I change it now to match. It is now called selectedVideo

Thanks for the assist brother. A huge W to you 🙂👍

#

Quick question for you though. I don't know how familiar you are with Astro but what is the best method for doing form submissions.

I know you can submit directly to an API Endpoint.
You can use an Astro action like I am doing here
You can also use an addeventlistener and then make fetech request

What is the best practice.

main granite
#

So the way you are doing it here. Allows for a zero JS form submission. It’s all handled on the server. You can also setup an API endpoint for form submissions. Or call the action client side in the JS. It just depends on you

#

What’s nice about doing it in the actions. You don’t need the Try Catch Block like you use.

glass pawn
#

How does Astro actions make the try catch block irrelevant

main granite
#

It’s got it built in. I’ll spin up an example and link it