Closed MohammadHarish52 closed 8 months ago
`export async function createPost(post: INewPost) { try { //upload image to storage const uploadedFile = await uploadFile(post.file[0]);
if (!uploadedFile) { 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); }
i am recieving this in error
fixed
what was the fix?
`export async function createPost(post: INewPost) { try { //upload image to storage const uploadedFile = await uploadFile(post.file[0]);
} catch (error) { console.log(error); }
}`
i am recieving this in error