Using Companion for getting access to Google Drive, etc

Hello!

I’m looking information if Transloadit solutions will be suitable for my company needs.

We’re developing application - (.Net WebApi + Angular frontend), but every client gets instalator and has own instance locally hosted - there is no web hosted app.

File upload from local drive to app is already implemented using TUS (tusdotnet on webapi side as server and tus-js-client on frontend side).

Now, we would like to extend functionality to have intergation with Google Drive/Dropbox/Box and allow users to select files from their webdrives and upload to our application for future processing. For now - no need to do anything with those files, just need to authorize, browse them and upload to our app.

I did a quick POC:

export class UploadManagerComponent
    extends ManageGenericListComponent
    implements OnInit
{
    private fileUploadUrl: string = getEndpoint('fileUploadUrl');
    public dashboardModalProps = {
        inline: true,
        width: 'auto',
    };
    public uppy: Uppy = new Uppy({
        debug: true,
        autoProceed: true,
    });
    constructor(
        protected readonly store: Store<fromRoot.State>,
        public readonly commonTab: CommonTabService,
        public readonly entityUpdateService: EntityUpdateService,
        public readonly tEngine: TranslationEngineService,
        public readonly iconService: CustomIconService,
        public readonly _confirmationService: ConfirmationService
    ) {
        super(
            store,
            entityUpdateService,
            _confirmationService,
            tEngine,
            iconService
        );
    }
    ngOnInit() {
        super.ngOnInit();
        const companionAllowedHosts = [
            'https://localhost:2402',
            'http://localhost:3020',
        ];
        const token = getAuthenticationToken();
        this.uppy.on('file-added', file => {
            console.warn('file added to uppy:', file);
            let importOptions: ImportOptionsMeta = {
                fileName: file.name,
            };
            this.uppy.setMeta({ importOptions: JSON.stringify(importOptions) });
        });
        this.uppy
            .use(Dashboard)
            .use(Transloadit, {
                assemblyOptions: {
                    params: {
                        auth: { key: 'auth key from Credentials sections in Transloadit portal' },
                    },
                },
            })
            .use(GoogleDrive, {
                companionUrl: 'https://companion.uppy.io/',
                companionAllowedHosts: companionAllowedHosts,
            })
            // .use(Dropbox, {
            //     companionUrl: 'https://companion.uppy.io',
            //     companionAllowedHosts: companionAllowedHosts,
            // })
            .use(Tus, {
                endpoint: this.fileUploadUrl,
                retryDelays: [0, 1000, 3000, 5000],
                headers: {
                    Authorization: `Bearer ${token}`,
                },
            });
    }
}

I setup locally hosted standalone companion app.
Created a google app so I get key and secret from google for authorization.
And it worked fine! (above code example is adjusted to use hosted companion)

Now, the question - we would like to avoid maintaining own Companion (and google, dropbox, box apps and all credentials related to it) and use Transloadit hosted companion. Tried to use https://companion.uppy.io mentioned in docs but cors are failing:

Access to fetch at 'https://companion.uppy.io/drive/list/root' from origin 'https://localhost:2402' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Is using Transloadit hosted Companion in such scenario even possible?
All requests will be always coming from https://localhost:2402, is it possible to configure cors somehow?

Would love to hear what are the options and implementation tips. Or if standalone app is the only way to handle that.

Regards,
Jakub

Hi, once this PR is merged: Allow Transloadit-hosted Companion with other uploaders by Murderlon · Pull Request #5558 · transloadit/uppy · GitHub

You can use Transloadit-hosted Companion only for your remote files and continue to use another uploader for you local files (in your case tus)

It would work like this:

  1. Sign up for Transloadit
  2. Create a template to export to S3
  3. Add your S3 credentials
  4. Configure Uppy to only use @uppy/transloadit for remote files:
import { COMPANION_URL, COMPANION_ALLOWED_HOSTS } from '@uppy/transloadit';

uppy.use(Tus, { /* ... */ })
uppy.use(Transloadit, { companionOnly: true /* ... */ })
uppy.use(Dropbox, {
	companionUrl: COMPANION_URL,
	companionAllowedHosts: COMPANION_ALLOWED_HOSTS,
});

Thanks for reply - it looks like something we can use!

But, export to S3 will be needed? Or it’s just an empty template cause I need to have some template to get COMPANION_URL?

And what would be the correct COMPANION_URL? The one mentioned in doc is for general use (https://companion.uppy.io) ?
Or do I need to create own empty assembly/template? Reading docs, can’t really figure it out.

Sorry I was mistaken that your files end up in S3. You can use any export robot.

You can never use https://companion.uppy.io, it’s only for https://uppy.io/examples. You can import the URL for hosted companion from @uppy/transloadit (or hardcode to https://api2.transloadit.com/companion)

Note that until that PR is merged your would also have to use @uppy/transloadit for your local files.

Regarding export robot - the TUS server is hosted locally. Every client has own, local hosted application (and own local hosted TUS server - not available over internet) so I guess I can’t use any of them.

All files must be handled locally on the user computer - companion is just needed to authorize for Google Drive/Dropbox/Box.

That’s my scenario I’m trying to figure out how to make it work.

https://api2.transloadit.com/companion - are there any quotas or limits for use?

What storage do you use with tus? If it’s file disk storage and the tus server is not reachable over the internet then it will be a bit harder. Perhaps you could use notify_url in your template to let your backend know when the file made it from Companion into Transloadit to then download and move it into the appropriate file storage.

Companion never sends files to the client, the whole point is that it saves bandwidth. With hosted Companion, your files must go through the Transloadit template flow. In there, you can use some Robots to forward your files to wherever needed.

If you only import and export, no other Robots, then you will pay for 10% of the file size that you move through Transloadit.

It’s a local blob storage. Backend does not have public ip, it’s just a local host on client computer - nothing I could use as notify_url.
So, I guess the standalone companion is the only way to handle that case.