Hello, I success to fetch every data to an mobile app, but to finish I need to get Image from my database. I get the wix format url like this => “wix:image://”
But I need to transform with full url. I tried this following (founded on this forum) on my “http-function” but I don’t know how call my function to get it. Can you help me please ?
(I readed all the day reference Velo’s doc but nothing founded…)
Thx
// In http-functions.js
import { ok , notFound , serverError } from ‘wix-http-functions’ ;
import wixData from ‘wix-data’ ;
const email = “contact@mizzup.com”
export function get_li () {
let options = {
“headers” : {
“Content-Type” : “application/json” ,
“Access-Control-Allow-Origin” : “*” ,
“Access-Control-Allow-Methods” : “POST, GET, OPTIONS” ,
}
};
// query a collection to find matching items
return wixData . query ( “RH” )
. eq ( “email” , email )
. find ()
. then ( ( results ) => {
// matching items were found
if ( results . items . length > 0 ) {
options . body = {
“photo” : results . items [ 0 ]. photo . r
};
return ok ( options );
}
// no matching items found
options . body = {
“error” : ' ${ email } ' was not found
};
return notFound ( options );
} )
// something went wrong
. catch ( ( error ) => {
options . body = {
“error” : error
};
return serverError ( options );
})
}
export function getFullImageURL ( imageSRC ) {
//convert the wix:image url to something that can be displayed inside html-component
let strReturnImage = “” ;
if ( imageSRC . startsWith ( “image:” )) {
let wixImageURL = “” ;
wixImageURL = “https://static.wixstatic.com/media/” ;
let wixLocalURL = “” ;
wixLocalURL = imageSRC . replace ( ‘image://v1/’ , ‘’ );
wixLocalURL = wixLocalURL . substr ( 0 , wixLocalURL . indexOf ( ‘/’ ));
strReturnImage = wixImageURL + wixLocalURL ;
}
else if ( imageSRC . startsWith ( “wix:image:” )) {
let wixImageURL = “” ;
wixImageURL = “https://static.wixstatic.com/media/” ;
let wixLocalURL = “” ;
wixLocalURL = imageSRC . replace ( ‘wix:image://v1/’ , ‘’ );
wixLocalURL = wixLocalURL . substr ( 0 , wixLocalURL . lastIndexOf ( ‘/’ ));
strReturnImage = wixImageURL + wixLocalURL ;
}
else {
strReturnImage = imageSRC ;
}
return strReturnImage ;
}