I get an error when using wix query to retrieve an image from a collection and then try to set the src method of a user input field of type image to the retrieved image.
The ERROR states that the src method parameter must be of type string NOT object. So, it is looking for the url not the actual image. How do I convert the image returned from the wix query from an object to a string? I tried toString() but that doesn’t work.
Here is the code:
getAllResources()
.then ( (results) => {
if (results.length > 0) {
$w(‘#table1’).rows = results;
//###################### debugging
// collection field resourcePicture is type Image
// input field $w("#picResource") is of type Image
**let** item = results[1];
**let** collectionImage = item.resourcePicture;
console.log("collectionImage: " + collectionImage); // type [object: Object]
$w("#picResource").src = collectionImage; //ERROR - src method parameter must be a string NOT object
//NOTE: image was inserted into collection using wix's upload file button
//####################### end debugging
}
})
export function getAllResources() {
return wixData.query(‘Resources_Index’)
.limit(100)
.find()
.then ( (results) => {
return results.items;
})
. catch ( (error) => {
let errorMsg = error.message;
let code = error.code;
console.log("getAllResoueces - Code: " + code + "Msg: " + errorMsg);
});
}