tus / tus-js-client

A pure JavaScript client for the tus resumable upload protocol
https://tus.io/
MIT License
2.09k stars 313 forks source link

How to set creator, Signed URL and Allowed Origins on Cloudflare TUS Upload #684

Open SheryarKhan6242 opened 5 months ago

SheryarKhan6242 commented 5 months ago

Question How to set the the creator id and signed url and Allowed orgins. Also can Allowed origins be a wild card ?

Setup details

Code:


        upload = new tus.Upload(file, {
            // endpoint: 'https://master.tus.io/files/',
            endpoint: 'https://api.cloudflare.com/client/v4/accounts/XXXXXXXXXXXXXX/stream',
            headers: {
                'X-Auth-Email': 'XXXXXXXXXXXXXXXX',
                'X-Auth-Key': 'XXXXXXXXXXXXXXXXXXXXXXXX'
            },
            chunkSize: 5 * 1024 * 1024,
            retryDelays: [0, 1000, 3000, 5000],
            creator: '123',
            requireSignedURLs: true,
            metadata: {
                name: videoName,
                filetype: file.type,
            },
            onError: function(error) {
                console.log('Upload error', error);
            },
            onProgress: function(bytesUploaded, bytesTotal) {
                console.log(bytesUploaded)
                var percentage = (bytesUploaded / bytesTotal * 100).toFixed(2);
                console.log('Upload progress', percentage + '%');
                progressBar.style.width = percentage + '%';
            },
            onSuccess: function() {
                console.log('Upload complete');
                uploadLabel.style.display = 'block';

            });`
Acconut commented 5 months ago

How to set the the creator id and signed url and Allowed orgins. Also can Allowed origins be a wild card ?

I don't know what these are. Please elaborate more.

SheryarKhan6242 commented 5 months ago

How to set the the creator id and signed url and Allowed orgins. Also can Allowed origins be a wild card ?

I don't know what these are. Please elaborate more.

This is the code that does resumable uploads on cloudflare stream. The js client that I'm using is https://github.com/tus/tus-js-client But I cannot find any option how to send creator and Signed option to set it on cloudflare

Acconut commented 5 months ago

What are "creator" and "Signed option"? I don't CloudFlare's API and thus cannot help you until you provide more details on what these terms mean and what you want to do with them. Maybe provide a link where this is explained.

SheryarKhan6242 commented 5 months ago

What are "creator" and "Signed option"? I don't CloudFlare's API and thus cannot help you until you provide more details on what these terms mean and what you want to do with them. Maybe provide a link where this is explained.

Apologies. Please refer to the following link for TUS(Large size file uploads) https://developers.cloudflare.com/stream/uploading-videos/upload-video-file/

You can also refer to curl documentation, but because I'm using tus js client, so the fields might differ.

https://developers.cloudflare.com/api/operations/stream-videos-upload-videos-via-direct-upload-ur-ls

I wanted to know how can I achieve this using my tus js client to pass the creator id and the other 2 params I mentioned.

Acconut commented 4 months ago

Those links helped, thanks.

requiresignedurls and allowedorigins should be set via the metadata option in tus-js-client. For the creator property, set Upload-Creator in the headers option.

I hope this helps!