Not receiving image url's in Fetch request of all Post

Hey,
I am trying to fetch the Global post of the user using the function below.

    const queryParams = {
      targetType: "global",
      sortBy: "lastCreated",
      includeDeletedPosts:  true,
      limit: query.pageSize ?? 20,
    };
      const liveCollection = await PostRepository.queryPosts(queryParams);

      let response = await new Promise((resolve) => {
        liveCollection.on("dataUpdated", (posts) => {
          resolve(posts);
        });
      });

However, I am not receiving Image URLs of the posts from the response array. The attachments key is coming as undefined.

Please provide a solution to get the uploaded file URLs in the Listing API.

I also noticed sometimes the response I am receiving from the API is not accurate. I have added a filter includeDeletedPosts: true, but this filter does not work all the time. Especially when I fetch the data for the first time.

I am using amity js SDK "@amityco/js-sdk": "^5.37.0".

Hello, our team will help provide the code for the global feed query first. Once you have applied the correct code, we will further check for the existing issues.

1 Like

Hello, Any update on this?

We have updated the code here: Query Global Feed - Amity Docs please apply this code and observe if the other issues still occur.

Hey,
Global feed APIs return my posts & the posts of the users I am following but I want to see only my posts. Is there any filter I can use to fetch only my posts?

Are you referring to user’s feed, where contains posts you have posted on your personal feed? or posts that you have posted in communities?

Is it possible to get both a user’s feed and a community feed? Only my post (both user and community) in a single API call?

Unfortunately, no. The APIs you can use for querying posts, whether from a community or a user feed, are as follows:

  1. Query Posts API: This API allows you to retrieve posts from user or community.
  2. User Feed API: It enables you to fetch a paginated list of posts from a user’s feed.

Okay, How about the files URL on listing API’s? I tried in both Community post API and User feed API. I am not receiving file urls in js/sdk. but Flutter SDK is returning the file URLs in the list APIs only.

I am taking example of below function:

      const liveCollection = await PostRepository.queryPosts(queryParams);

      let response = await new Promise((resolve) => {
        liveCollection.on("dataUpdated", (posts) => {
          resolve(posts);
        });
      });

If I upload an Image on the user feed I get this type of response

        {
            "_id": "6502deee06d",
            "path": "64a3333/social/user/64ffe15d7f63c/post/6502deee06d",
            "sharedCount": 0,
            "targetType": "user",
            "dataType": "text",
            "commentsCount": 0,
            "editedAt": "2023-09-14T10:18:51.849Z",
            "createdAt": "2023-09-14T10:18:51.849Z",
            "updatedAt": "2023-09-14T10:18:51.852Z",
            "isDeleted": false,
            "hasFlaggedComment": false,
            "hasFlaggedChildren": false,
            "data": {
                "text": "geberal wuth image"
            },
            "postId": "6502de0bd7006d",
            "postedUserId": "6363629dd500d1d",
            "targetId": "6363629dd330d1d",
            "flagCount": 0,
            "hashFlag": null,
            "reactions": {},
            "reactionsCount": 0,
            "myReactions": [],
            "comments": [],
            "children": [
                "6502de0b6656666565e070"
            ],
            "mentionees": [],
            "tags": []
        },

There is no file URL, Now I have to make an API call to fetch the details of below child post.

"children": [
                "6502de0b5656565ee070"
            ],

Once I receive data then again I have to fetch the file from the file Id I get from child data.

I am making 2 extra calls just to fetch the image/video URL.

But in Flutter SDK Image url’s are coming directly on the listing API.

How can I directly get the URLs on the list API’s?

If there is an image/file in that post, it should return the fileId this is an example via api call.

Could you pls share the steps you create that image post?

// Create video file

const createVideoFile = async (fileObject) => {
  const liveFile = FileRepository.createVideo({ file: fileObject });
  const model = await new Promise((resolve) =>
    liveFile.once("dataUpdated", (data) => resolve(data))
  );
  return model;
};

// post user feed

const postNewsFeed = async (data) => {
  try {
      const payload = {
        targetType: PostTargetType.UserFeed,
        targetId:  // targetId
        text: data.text,
      };


        const amityFile = await createVideoFile(data.videoIds[0]);
        payload.videoIds = [amityFile.fileId];

      const livePost = PostRepository.createVideoPost(payload);

      let response = await new Promise((resolve) => {
        livePost.once("dataUpdated", (model) => {
          resolve(model);
        });
      });

      livePost.on("dataError", (error) => {
        console.log(error, "error");
        throw Error(error);
      });

      return response;
    }
  } catch (error) {
    console.log(error);
    throw Error(error);
  }
};

After making the above call this is how my payload looks like in network tab

{
  "attachments": [
    {
      "fileId": "65031f4d3f3187907c0e26a4",
      "type": "video"
    }
  ],
  "metadata": {},
  "targetType": "user",
  "targetId": "6363629dd",
  "data": {
    "text": "Posting video feed"
  }
}

And this is the response from the API (I am sharing only post object I do get other object like “postChildren”, “user” etc…)

{
    "posts": [
        {
            "_id": "65031f5f287db2cc0",
            "path": "64a67c52725b00292f5f3333/social/user/64feaeca62c509fe15d7f63c/post/65031f5f287db2ceae8127c0",
            "sharedCount": 0,
            "targetType": "user",
            "dataType": "text",

            "commentsCount": 0,
            "editedAt": "2023-09-14T14:57:35.324Z",
            "createdAt": "2023-09-14T14:57:35.324Z",
            "updatedAt": "2023-09-14T14:57:35.328Z",
            "isDeleted": false,
            "hasFlaggedComment": false,
            "hasFlaggedChildren": false,
            "data": {
                "text": "Posting video feed"
            },
            "postId": "65031f5f287d127c0",
            "postedUserId": "6363629500d1d",
            "targetId": "6363629d500d1d",
            "flagCount": 0,
            "hashFlag": null,
            "reactions": {},
            "reactionsCount": 0,
            "myReactions": [],
            "comments": [],
            "children": [
                "65031f5f287db2aeae8127c3"
            ],
            "mentionees": [],
            "tags": []
        }
    ],

The same response I am getting in the listing. There are no URL’s

Did you upload the file to our platform before creating the post? You can refer to this documentation: Upload Videos, or utilize the APIs outlined in this section: File APIs. After uploading the file, it will return a fileId, which you can then include when creating the post.

const createVideoFile = async (fileObject) => {
  const liveFile = FileRepository.createVideo({ file: fileObject });
  const model = await new Promise((resolve) =>
    liveFile.once("dataUpdated", (data) => resolve(data))
  );
  return model;
};

I am using this function to upload file on your platform.

Please note: File issue is happening only in JS/SDK but Flutter SDK is sending file URLs for the same posts.

May I ask what is your current sdk version please?

"@amityco/js-sdk": "^5.37.0" .

Got it, let us double check and will get back to you. Thank you for your cooperation and providing all the required information :slightly_smiling_face:

1 Like

Hi @Ashish , The image posts will be appeared as children inside the parent post. You can use PostRepository.postForId('6502de0b5656565ee070') to query the image post detail. After you get the fileId, you can just put the fileId into this url https://api.amity.co/api/v3/files/{fileId}/download?size=full (size can be small, medium, large, full). No extra query needed to get the imageUrl.

Hey,
Don’t you think making the network request for getting the image URL is not a good approach?

I am rendering 20 posts at once and making the network request for all 20 posts will make the application slow.

Hey,
The above method also not working. I called the API and got the file ID. But the URL you have provided is not working.

Refer to the image I have received the fileId.
Screenshot from 2023-09-17 10-48-08

Now if I append the ID on the URL I get the error
https://api.amity.co/api/v3/files/4cde9d2ccc5f48c7a27a0e5ffa29a739/download?size=full

{
    "status": "error",
    "message": "File not found 4cde9d2ccc5f48c7a27a0e5ffa29a739",
    "code": 400400,
    "data": {
        "detail": {}
    }
}

This is happening for all the files.

In that case, Can you try specify the region inside the URL?

https://api.us.amity.co/api/v3/files/4cde9d2ccc5f48c7a27a0e5ffa29a739/download?size=full

1 Like