Object Storage
Retrieve profile pictures

Retrieving Profile Pictures

When working with the Rscripts API, you may need to display profile pictures associated with scripts. The API provides a way to retrieve profile pictures based on the presence of a user object and the image field within it.

Retrieving Profile Picture URL

To retrieve the profile picture URL, you can follow this logic:

// Handle profile picture
const hasUser = script.user.length;
const profilePicture = hasUser > 0 ? script.user[0].image : null;
const profilePictureUrl = profilePicture
 ? `https://rscripts.net/assets/avatars/${script.user[0].image}`
 : `https://i.pravatar.cc/300`;

In this code snippet:

  1. hasUser checks if the user array in the script object is not empty.
  2. If hasUser is greater than 0 (i.e., the user array is not empty), the profilePicture is set to the value of script.user[0].image. Otherwise, it is set to null.
  3. The profilePictureUrl is constructed based on the value of profilePicture:
  • If profilePicture is not null, the URL is https://rscripts.net/assets/avatars/${script.user[0].image}, which points to the user's avatar image stored on the S3 bucket.
  • If profilePicture is null, a placeholder avatar URL from https://i.pravatar.cc/300 is used.


Once you have the profilePictureUrl, you can use it to display the profile picture in your application. For example, you can create an <img> element and set its src attribute to the profilePictureUrl:

<img src="${profilePictureUrl}" alt="Profile Picture" />