I'm not sure about SvelteKit
But I think this line
post: { bucketId: createBucket }Will be sent sync, meaning you won't get the createBucket value.
You must add some await in that post
Votes
0
Replies
24
Participants
Unknown
Messages
25
I'm not sure about SvelteKit
But I think this line
post: { bucketId: createBucket }Will be sent sync, meaning you won't get the createBucket value.
You must add some await in that post
Rank 3: Container
return { post: { bucketId: await createBucket } };}```I can do thisBut you'll to wait to the createProject function
Or something similar to this
async function getBucket() { const bucketId = await actions.createProject(/* Pass your data*/); return bucketId;}
export async function load() { return { post: { bucketId: await getBucket() } };}Rank 3: Container
import sdk, { ID, Permission, Role } from 'node-appwrite';import { PUBLIC_API_ENDPOINT, PUBLIC_PROJECT_ID } from '$env/static/public';import { PRIVATE_API_KEY } from '$env/static/private';
const client = new sdk.Client();// const account = new sdk.Account(client);// const databases = new sdk.Databases(client);const storage = new sdk.Storage(client);
client .setEndpoint(PUBLIC_API_ENDPOINT) // Your API Endpoint .setProject(PUBLIC_PROJECT_ID) // Your project ID .setKey(PRIVATE_API_KEY); // Your secret API key
let createBucket;
export const actions = { createProject: async ({ request }) => { const formData = await request.formData(); const Client = formData.get('Client');
createBucket = await storage.createBucket(ID.unique(), Client, [ Permission.create(Role.user('64b1c7848008d470d744')), Permission.update(Role.user('64b1c7848008d470d744')), Permission.read(Role.user('64b1c7848008d470d744')) ]);
// bucketId = createBucket.$id
console.log(createBucket.$id);
// console.log(Client); }, imgUpload: async ({ request }) => {}};
export async function load() { return { post: { bucketId: createBucket } };}This works just fine. So here is the output of the id on the client-side
Rank 3: Container
This one is the id of the bucket it created before this last one.
64b4752051094e8fd08f Outside timeout
This one is correct
64b4753caa58d8fe56de Outside timeout
So you first send a form action to createPost and only then you're checking for data.post.bucketId?
From what I see the second will happened first make you get the bucket ID each time.
Rank 3: Container
action="?/createProject" method="post" on:submit|preventDefault={onSubmit} class="flex flex-col justify-center mt-5" use:enhance >```Rank 3: Container
use:enhance allows me to send form data to both client and server side using post method for server side and on:submit for client side function
I see,
Probably it best to wait for some one more expert in using 
What I think it has to do with the fact that bucketId is sent back before the form has ben submitted
Rank 3: Container
The form is submitted when the onSubmit funtion runs and when the from actions is ran
Rank 3: Container
Thank you for your time
Rank 3: Container
Getting form file input from server side (Svelte)
Why are you creating buckets at runtime like this?
Rank 3: Container
I was going to create a bucket for each set of image to keep database organized
What do you mean by set of image?
Rank 3: Container
Set of images sorry.
Rank 3: Container
Like one project Might have 4 img and I want then to all be together
Rank 3: Container
@Steven
For each user? I still don't really understand
Rank 3: Container
Each of these is a project. This is for a portfilio page, I want to have a set of img for each project that is in their own buckets
I typically advise against creating collections or buckets at runtime like this
Rank 3: Container
Interresting why is that?
Rank 3: Container
just like complications
A simple flat design is easier to maintain. A collection or bucket should be a type of data. If you have the same type of data in multiple collections or buckets, you should really have a good reason for it
Rank 3: Container
Ok thank you I will just stay with one storage bucket then