Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is file uploading provided in this lite client? #9

Closed
0000sir opened this issue Sep 2, 2017 · 8 comments
Closed

Is file uploading provided in this lite client? #9

0000sir opened this issue Sep 2, 2017 · 8 comments

Comments

@0000sir
Copy link

0000sir commented Sep 2, 2017

It's great to find this project, I'm implementing my own guacamole client, but stuck in file uploading.

I have no idea about how to upload files as described in guacamole-client docs, is it provided in guacamole-common-js or I have to write every thing myself?

Do you get file uploading works? How? Thanks very much.

@vadimpronin
Copy link
Owner

vadimpronin commented Sep 2, 2017

We do have working file uploads, but we use guacamole-common-js version 0.9.9. My colleague told me that versions up to 0.9.9 used websockets for file uploads, while versions 0.9.10 and above use HTTP uploads. I didn't check/confirm it myself though.

So I suggest that you try guacamole-common-js 0.9.9 in the first place.
And probably some time later I'll take a look on versions 0.9.10+ and see if the new upload method can be implemented in guacamole-lite.

@vadimpronin
Copy link
Owner

As a quick note: downgrading guacamole-common-js to 0.9.9 doesn't mean you have to downgrade guacd as well. We have guacamole-common-js v0.9.9 working very well with guacd v0.9.11. So if you need any features of the latest release you can still have them

@0000sir
Copy link
Author

0000sir commented Sep 7, 2017

Thanks for that, I checked the js api, but still don't know how to do it, may be the BlobWriter ? I'm trying to include the whole guacamole-client to my project, with a nginx for proxy, but have more problem to deal with -_-!..

@vadimpronin
Copy link
Owner

vadimpronin commented Sep 7, 2017

This is the function we use for uploading files with guacamole-common-js 0.9.9:

  uploadFile = file => {
    const _this      = this;
    const fileUpload = {};
    const reader     = new FileReader();

    reader.onloadend = function fileContentsLoaded() {
      const stream = _this.client.createFileStream(file.type, file.name);
      const bytes  = new Uint8Array(reader.result);

      let offset   = 0;
      let progress = 0;

      fileUpload.name     = file.name;
      fileUpload.mimetype = file.type;
      fileUpload.length   = bytes.length;

      stream.onack = function ackReceived(status) {
        if (status.isError()) {
          console.log('Error uploading file');

          return false;
        }

        const slice  = bytes.subarray(offset, offset + STREAM_BLOB_SIZE);
        const base64 = getBase64(slice);

        // Write packet
        stream.sendBlob(base64);

        // Advance to next packet
        offset += STREAM_BLOB_SIZE;

        if (offset >= bytes.length) {
          progress = 100;
          stream.sendEnd();
        } else {
          progress = Math.floor(offset / bytes.length * 100);
        }

        // Send progress to file upload's popup
        _this.uploadProgress.setProgress({
          name: file.name,
          progress: progress
        });
      }
    };

    reader.readAsArrayBuffer(file);

    return fileUpload;
  };

Hope that helps

@0000sir
Copy link
Author

0000sir commented Sep 7, 2017

Seems enough for me. That's very nice of you, I'll try this later because I'm meeting the deadline of glue the huge guac-client to my project, it's really ugly and slow, but it works at least, someone is going to use it online tomorrow...
After tomorrow, I will refactor these based on your codes.

Really really thank you.

@0000sir
Copy link
Author

0000sir commented Sep 9, 2017

Hey vadimpronin, I did it, much easier than gluing the original guac-client, that's great!

Thanks for your help, I should try this earlier.

And your codes work in guacamole-common-js 0.9.13, no need for changing anything

I think we can close this topic now. Thank you again.

@deg0nz
Copy link

deg0nz commented Dec 22, 2020

For future readers:

As described in #27, file upload still works via websocket on guacd and guacamole-common-js 1.2.0 with guacamole-lite

@mfarkan
Copy link

mfarkan commented May 13, 2021

@deg0nz @vadimpronin hello, how this feature works ? Should i use input file element to pick a file but how does guacd understand which folder it will put into ?Am i missing something ? Is it possible to use just guacmole-common.js for sending file ?

I use 1.3.0 version of gua-common-js

Regards,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants