In my initial implementation, I returned result.href
directly, which caused unexpected behavior. To fix this, I needed to return the entire response object from the getFilePreview
method and then access the URL. By returning the full response, I was able to correctly retrieve the image preview URL.
So instead of return result.href
, simply return the full response object and then access the URL where needed.
async getFilePreview(fileId) {
if (!fileId) {
throw new Error("File ID is required.");
}
try {
const result = await this.bucket.getFilePreview(
conf.appwriteListingImagesBucketId,
fileId,
1800, // width
0, // height (ignored when 0)
"center", // crop center
"90", // compression
5, // border width
"CDCA30", // border color
15, // border radius
1, // full opacity
0, // no rotation
"FFFFFF", // background color
"jpg" // output format
);
return result; // Return the entire response object instead of just result.href
} catch (error) {
console.error("Error fetching file preview:", error);
throw new Error("Failed to fetch file preview.");
}
}