When I run this code, there are no new posts created in my Amity dashboard. Am I missing something?
<script>
import { PostRepository, FileRepository, PostTargetType } from '@amityco/js-sdk';
import AmityClient from '@amityco/js-sdk';
const client = new AmityClient({
apiKey: {API_KEY},
apiRegion: "US",
});
// Function to upload file to Amity
const uploadFile = async () => {
// Get file object from the HTML form
const fileObject = document.getElementsByName("file")[0].files[0];
// Create the file on Amity
const amityFile = await createFile(fileObject);
// Create the image post with the uploaded file
await createImagePost(amityFile.fileId);
// Reset the form
document.getElementsByTagName("form")[0].reset();
};
// Function to create a file on Amity
const createFile = async (fileObject) => {
const liveFile = FileRepository.createFile({ file: fileObject });
const model = await new Promise((resolve) =>
liveFile.once("dataUpdated", (data) => resolve(data))
);
return model;
};
// Function to create an image post on Amity
const createImagePost = async (fileId) => {
await PostRepository.createImagePost({
targetId: "user1",
targetType: PostTargetType.CommunityFeed, // PostTargetType.CommunityFeed for community feed or PostTargetType.UserFeed for user profile feed
tags: ["a", "b"],
imageIds: [fileId],
});
};
</script>
<!-- HTML form to upload a file -->
<form enctype="multipart/form-data">
<input type="file" name="file">
<button type="submit" on:click|preventDefault={uploadFile}>Upload</button>
</form>