Looking for a way to directly and immediately access a ServerConnect’s data upon calling load.
Trying to accomplish something like this: serverconnectname.load().data.variable
I know the serverconnect’s “on success” ability can be used for accessing the data, and that the data can be accessed after calling load() separately by serverconnectname.data.variable
But I assume there must be a way to load the serverconnect and access the data immediately after loading, for instance dynamically specifying the source for an image, something like:
src=“serverconnectname.load({original_url: url}).data.new_url”
Can anyone help with the correct syntax for this?
Thanks in advance!
On the frontend there is no more direct way than the way Wappler already handles this.
As it’s an AJAX call you need to wait for asynchronous call to return the data.
Just bind the data to the attribute as apple suggested and it will load the image as soon as it’s available. It’s how reactive frameworks work.
Or if you want it to be available on page render and not have to make the ajax SC call you could use server side rendering to inject the src before the page actually renders.
problem is not in the binding, I understand dmx-bind, what I’m looking for is the syntax to load a serverconnect and then access its data in a single statement that can then be placed anywhere and resolved immediately when the statement is processed… similar to how you can include a where() function within a statement and then continue on processing its result:
data.array.where(some conditions).result.element
trying to find the syntax to do this with serverconnect functions…
this is just an example statement that is intended to load the serverconnect and immediately continue the statement to access results: serverconnectname.load({original_url: url}).data.new_url
Where is not an asynchronous function while loading a server connect is. Therefore even if that was the syntax you wouldn’t be able to access its data without handling its asynchronous nature.
Or maybe we are not understanding correctly your problem. To avoid falling in an XY problem maybe you can let us know what are the requirements of the functionality you are trying to implement and what should the end result look like.
Thanks JonL, yes it sounds like the fact that server connect is asynchronous is why this wouldn’t work, but maybe you can suggest another method to accomplish what I specifically need. Basically I have many repeaters that bring S3 private image URLs from various sources and data structures, and I need to dynamically convert them to S3 signed URLs right before displaying them. I created a server connect that takes a private URL and uses the S3 Sign Download URL action to obtain the associated signed URL to dispay: scGetSignedURL.load({privateUrl: private_URL})
My issue is figuring out how to use this server connect from within my repeaters to process the URLs immediately prior to display. It needs to be loaded many times while repeating through my elements, and I’m not sure where I could place the server connect load statement within my repeaters. I also suspect that I can’t simply have each repeater access the data associated with this asynchronous server connect because it would probably end up overwriting each time it is loaded and then the final signed URL to be received would end up being displayed for all the images.
Is there any way to make a synchronous function using the S3 Sign Download URL action instead that will simply perform the processing and return the result? not sure if server side rendering would accomplish this, but any other suggestions would be appreciated, thanks!
Can’t you not do all that on the backend and send to the browser only the signed url? Retrieve the list of URLs on the backend, sign them, and send them to the browser?
I’m using the Wappler S3 functionality to upload the images/files to the S3 bucket, then I save the private URLs in my backend/database (via server connect APIs), when these private URLs are later sent back to the front end, I then need to use the Wappler S3 Sign Download URL action to convert them to signed URLs prior to display. I believe this is the correct flow for using the Wappler S3 capabilities, and it works fine for a simple page with a fixed number of images… however, I need it to work within repeaters that pull image URLs from multiple sources and data structures.
I’m not sure how to use the Wappler S3 Sign Download URL action within some other form of “backend” rather than a Wappler server connect, which my APIs would then somehow need to communicate with, prior to sending to the browser… of course I can go back to trying to figure out how to have my backend (PHP-based) request the signed URLs directly from the S3 bucket. I did attempt doing all the S3 communication directly through my backend, but was not successful… then found that Wappler has the S3 capability built-in and was able to quickly get the images stored up to the S3 bucket, now I just need to finish the process by using the Wappler S3 capability to sign the URLs.
Why not merge all the URL sources into one data structure, send to the backend, sign them, send them back to the browser, and use that as the data source of a repeat?
how can I use Wappler S3 Sign Download URL action in a “backend”? I can think of creating a Wappler server connect that places the S3 Sign Download URL action in a loop (maybe a while statement, or using a repeat) to process a list of URLs… but not sure if that would actually work. Is there another way to use the Wappler S3 Sign Download URL action in a backend that I’m not aware of?
As an alternative. Can’t you not create a bucket per user and use bucket policies to restrict that only an authorized user can read from his bucket? I guess not because you spoke about having several sources where you read the private urls from so it seems the process is not highly streamlined per user.
sure, I could create a bucket for each user, but I’m currently creating a folder for each user on a single bucket… if each user had their own bucket, not sure how that would help because I’d still need to sign all the URLs I provide to them… and there are many I need to dynamically present to a user based on various conditions.
Thanks for your help, I’ll try a server connect that loops through a list of URLs and see if that works. Otherwise, I guess I’ll need to put more effort into directly accessing S3 via my PHP backend without using Wappler.
reaching dead ends… going back to basics here… is there any way to get a server connect to load when an image is being displayed?
for instance, I just need an event to get my server connect to start processing when this statement is encountered:
<img dmx-bind:src=“serverconnectname.data.signed_URL”>
I’ve tried everything I can think of, including dmx-on:load event:
dmx-on:load=“serverconnectname.load({original_url: url})”
but that seems to only get triggered once there is an image available to load. I’ve also tried conditions, but with no luck.
Stated even more generally, is there any way to trigger/load a server connect from ANY statement, whether it’s an image, a button, a <div>, etc… ??
What’s the purpose of this, i don’t get the whole logic in this topic?
In your server action get your s3 files list, repeat through it and use the sign download option and get the signed urls.
Then build your repeat with the images on the page using this server action as a source.
building a single list of URLs ahead of time is difficult in my situation since I have many sources coming in with different structures in each, and the repeaters that I’ve already created do all the sifting through them already… so this comes down to a more basic question I have, which if solved will help me in many other ways as well:
is there any syntax to trigger a server connect to start loading (or even running a flow) exactly when a statement is reached, or by including it in the statement somehow? for instance:
<img _______ >
<div ________ >
<p ________>
I’ve also tried using the onupdated="" and onupdate="" events associated with the repeaters, which seems most logical to me… but the data being iterated in the repeat doesn’t seem to be available when I use them as parameters to my server connect placed within these events. I’d think this is the best place to run my server connect since it relies on the data from each iteration of the repeat, but maybe the onupdated syntax I’ve used in incorrect, or the purpose of onupdated is not what I’m expecting:
summarizing my question:
how can someone trigger a server connect (or run a flow) at each iteration of a repeat, so that the server connect (or flow) can take as input the data associated with each repeat iteration?
simple hypothetical example:
a repeater iterates through objects that have 5 datapoints each, we want to send the 5th datapoint of each iteration to a log via a server connect, how would you do that?