On Thu, May 27, 2021 at 11:59 AM dkaranam002 <[email protected]>
wrote:
> Hi,
>
> This is the code I have:
>
> --------------------------------------------------------
> // File handler
> guac.onfile = function(stream, mimetype, filename) {
> console.log("Stream: ", stream)
> console.log("Mime type: ", mimetype)
> console.log("File name: ", filename)
>
> if (!window.location.origin)
> var streamOrigin = window.location.protocol + '//' +
> window.location.hostname + (window.location.port ? (':' +
> window.location.port) : '');
> else
> var streamOrigin = window.location.origin;
>
> console.log("Stream origin: ", streamOrigin)
>
> // Build download URL
> var url = streamOrigin
> + window.location.pathname
> + '/api/session/tunnels/' + encodeURIComponent(tunnel.uuid)
> + '/streams/' + encodeURIComponent(stream.index)
> + '/' + encodeURIComponent(filename.replace(/[\\\/]+/g, '_'))
> //+ '?token=' + encodeURIComponent(myToken);
> console.log("URL: ", url)
> console.log("Tunnel: ", tunnel)
> ...
>
Is this for a custom web application of your own?
Everything beneath ".../api/" that you see within the mainline Guacamole
web application is the REST API implemented by that web application
specifically, not part of the common Guacamole core APIs like
guacamole-common or guacamole-common-js. If you want to provide the
functionality of that or any other endpoint, you would need to implement a
similar endpoint with similar functionality.
You don't strictly *need* such an endpoint to facilitate a download - it's
possible to handle a file download purely via JavaScript. This is how
things were done before that endpoint was implemented:
https://github.com/apache/guacamole-client/blob/0ef7b90619a6895ba12e126dc344301400428edb/guacamole/src/main/webapp/app/client/types/ManagedClient.js#L454-L459
https://github.com/apache/guacamole-client/blob/0ef7b90619a6895ba12e126dc344301400428edb/guacamole/src/main/webapp/app/client/types/ManagedFileDownload.js#L99-L149
Overall, you would:
1) Use a Guacamole.BlobReader to assemble a Blob containing the transferred
file contents
2) When the Blob is assembled, leverage something like the W3C download API
to download the Blob as a file.
The fancy new technique now leveraged by the mainline webapp is to provide
a REST endpoint that leverages a FilteredGuacamoleReader to intercept
stream contents upon request:
https://github.com/apache/guacamole-client/blob/c431e9e22d63c24b87d3274db2bd411c8b864a78/guacamole/src/main/java/org/apache/guacamole/tunnel/StreamInterceptingTunnel.java
You can implement the above with standard Guacamole objects, but doing so
is definitely more complex.
Michael Jumper
CEO, Lead Developer
Glyptodon Inc <https://glyp.to/>.