Open shreyzeous21 opened 8 months ago
maybe you did not set the permissions for storage, i tried and it worked (go to Storage ->Media->Settings->Permissions->any->choose alls->update )
I have a similar problem. My photo is stored, but is NOT posted in the database.
maybe you did not set the permissions for storage, i tried and it worked (go to Storage ->Media->Settings->Permissions->any->choose alls->update )
I've already done this.
Here is my issue:
maybe you did not set the permissions for storage, i tried and it worked (go to Storage ->Media->Settings->Permissions->any->choose alls->update )
I've already done this.
Here is my issue:
please check you added attribute : imageUrl into Collection :Posts or not , check Spelling attribute : imageUrl (imageUrl , not ImageUrl )
Sorry, I solved the issue a while ago and just saw your message now. You're right.
I capitalized ImageUrl.
It was supposed to be imageUrl.
i am able to create a post but it is not coming in the posts database, there are no errors in the console and I am getting redirected also.
i am able to create a post but it is not coming in the posts database, there are no errors in the console and I am getting redirected also.
Make sure you set permission for all collections, try it
i am able to create a post but it is not coming in the posts database, there are no errors in the console and I am getting redirected also.
Make sure you set permission for all collections, try it
my permissions are ok maybe that i haven't added the create post as of timestamp 3h 18 minutes i am adding all the functions in api.ts and letting you know then
i am able to create a post but it is not coming in the posts database, there are no errors in the console and I am getting redirected also.
Make sure you set permission for all collections, try it
my permissions are ok maybe that i haven't added the create post as of timestamp 3h 18 minutes i am adding all the functions in api.ts and letting you know then
I did not fix any code, follow video and step by step with setup, I think the problem is not in api.ts
i am able to create a post but it is not coming in the posts database, there are no errors in the console and I am getting redirected also.
Make sure you set permission for all collections, try it
my permissions are ok maybe that i haven't added the create post as of timestamp 3h 18 minutes i am adding all the functions in api.ts and letting you know then
I did not fix any code, follow video and step by step with setup, I think the problem is not in api.ts
Sir i am talking about createpost and its related functions like upload file and alll
i am able to create a post but it is not coming in the posts database, there are no errors in the console and I am getting redirected also.
Make sure you set permission for all collections, try it
my permissions are ok maybe that i haven't added the create post as of timestamp 3h 18 minutes i am adding all the functions in api.ts and letting you know then
I did not fix any code, follow video and step by step with setup, I think the problem is not in api.ts
AppwriteException: Missing required parameter: "file"
at Storage.
my code
import { INewPost, INewUser } from "@/types"; import { ID, Query } from "appwrite"; import { account, appwriteConfig, avatars, databases, storage } from "./config";
// Function to create a new user account export async function createUSerAccount(user: INewUser) { try { // Create a new account with Appwrite const newAccount = await account.create( ID.unique(), user.email, user.password, user.name );
if (!newAccount) throw Error;
// Generate an avatar URL for the user
const avatarUrl = avatars.getInitials(user.name);
// Save user information to the database
const newUser = await saveUserToDB({
accountId: newAccount.$id,
name: newAccount.name,
email: newAccount.email,
username: user.username,
imageUrl: avatarUrl,
});
return newUser;
} catch (error) { console.log(error); return error; } }
// Function to save user information to the database export async function saveUserToDB(user: { email: string; name: string; accountId: string; imageUrl: URL; username?: string; }) { try { const newUser = await databases.createDocument( appwriteConfig.databaseId, appwriteConfig.userCollectionId, ID.unique(), user ); return newUser; } catch (error) { console.log(error); } }
// Function to sign in with an email and password export async function signInAccount(user: { email: string; password: string }) { try { // Create a session for the user const session = await account.createEmailSession(user.email, user.password); return session; } catch (error) { console.log(error); } }
// Function to get the current user's information export async function getCurrentUser() { try { // Get the current account information from Appwrite const currentAccount = await account.get();
if (!currentAccount) throw error;
// Query the database for the user's information using the account ID
const currentUser = await databases.listDocuments(
appwriteConfig.databaseId,
appwriteConfig.userCollectionId,
[Query.equal("accountId", currentAccount.$id)]
);
if (!currentUser) throw Error;
return currentUser.documents[0];
} catch (error) { console.log(error); } }
export async function signOutAccount() { try { // Delete the current session const session = await account.deleteSession("current"); return session; } catch (error) { console.log(error); } }
export async function createPost(post: INewPost) { try { //upload image to storage const uploadedFile = await uploadFile(post.file[0]);
if (!uploadFile) {
throw Error;
}
// Get file url
const fileUrl = getFilePreview(uploadedFile.$id);
if (!fileUrl) {
deleteFile(uploadedFile.$id);
throw Error;
}
// convert tags into an array
const tags = post.tags?.replace(/ /g, "").split(",") || [];
// save post to database
const newPost = await databases.createDocument(
appwriteConfig.databaseId,
appwriteConfig.postsCollectionId,
ID.unique(),
{
creator: post.userId,
caption: post.caption,
location: post.location,
imageUrl: fileUrl,
imageId: uploadedFile?.$id,
tags: tags,
}
);
if (!newPost) {
await deleteFile(uploadedFile?.$id);
throw Error;
}
return newPost;
} catch (error) { console.log(error); } }
export async function deleteFile(fileId: string) { try { await storage.deleteFile(appwriteConfig.storageId, fileId); return { status: "ok" }; } catch (error) { console.log(error); } }
export async function uploadFile(file: File) { try { const uploadFile = await storage.createFile( appwriteConfig.storageId, ID.unique(), file ); return uploadFile; } catch (error) { console.log(error); } }
export async function getFilePreview(fileId: string) { try { const fileUrl = storage.getFilePreview( appwriteConfig.storageId, fileId, 2000, 2000, "top", 100 ); return fileUrl; } catch (error) { console.log(error); } }
you chose file before you click button create post or not ?
i used author's code and it s no problem , you re coding yourself ?
i used author's code and it s no problem , you re coding yourself ?
There was typo in passing props in The section of Add photos were i gave the name to Add photos instead it should be file . Took me a long to realised but its fixed now
maybe you did not set the permissions for storage, i tried and it worked (go to Storage ->Media->Settings->Permissions->any->choose alls->update )
I've already done this.
Here is my issue:
There is a typo It should be "imageUrl"
Code snippet :
please help with this error, everything seems correct from my side..
Our fileUrl is getting an promise. so we have to only add await in front of getFilePreview(uploadedFile.$id);
AppwriteException: Invalid document structure: Attribute "imageUrl" has invalid format. Value must be a valid URL
at Client.
this error is coming and i can't create post but image is being stored.
please fix with my problem am getting problem in creating the post