Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>tus-js-client demo - Gcore Streaming Platform File Upload</title>
    <link
      href="https://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css"
      rel="stylesheet"
    />
  </head>
  <body>
    <div class="container">
      <h1>tus-js-client demo - Gcore Streaming Platform File Upload</h1>

      <p>
        This demo shows upload functionality of the tus protocol. You can select a file using the controls below and start/pause the upload as you wish.
      </p>
      <p>
        We support 2.x version of tus-js-client, look here: <a target="_blank" href="https://github.com/tus/tus-js-client/releases?q=v2.&expanded=true">https://github.com/tus/tus-js-client/releases?q=v2</a>
      </p>
      <p>
        For iOS and Android native apps look at our open source apps with full implementation: Android (<a target="_blank" href="https://github.com/G-Core/android-demo-vod-hosting">github</a>), iOS (<a target="_blank" href="https://github.com/G-Core/ios-demo-vod-hosting">github</a>). Other implementation you can find in official <a target="_blank"href="https://tus.io/implementations">tus.io</a> web site.
      </p>

      <div class="alert alert-warining hidden" id="support-alert">
        <b>Warning!</b> Your browser does not seem to support the features necessary to run
        tus-js-client. The buttons below may work but probably will fail silently.
      </div>

      <br />

      <table>
        <tr>
          <td>
            <label for="endpoint"> Upload endpoint: </label>
          </td>
          <td>
            <input
              type="text"
              id="endpoint"
              name="endpoint"
              value="https://vod-uploader-ed-2.gvideo.co/upload/"
            />
          </td>
        </tr>
        <tr>
          <td>
            <label for="chunksize"> Chunk size (bytes): </label>
          </td>
          <td>
            <input type="number" id="chunksize" name="chunksize" value="100000000" />
          </td>
        </tr>
        <tr>
          <td>
            <label for="token"> Token from GET: </label>
          </td>
          <td>
            <input
              type="text"
              id="token"
              name="token"
              value=""
            />            
          </td>
        </tr>
        <tr>
          <td>
            <label for="video_id"> Video ID from POST: </label>
          </td>
          <td>
            <input type="number" id="video_id" name="video_id" value="1" />
          </td>
        </tr>
        <tr>
          <td>
            <label for="client_id"> Your Client ID: </label>
          </td>
          <td>
            <input type="number" id="client_id" name="client_id" value="1" />
          </td>
        </tr>
        <tr>
          <td>
            <label for="paralleluploads"> Parallel upload requests: </label>
          </td>
          <td>
            <input type="number" id="paralleluploads" name="paralleluploads" value="1" />
          </td>
        </tr>
      </table>

      <br />

      <input type="file" />

      <br />
      <br />

      <div class="row">
        <div class="span8">
          <div class="progress progress-striped progress-success">
            <div class="bar" style="width: 0%"></div>
          </div>
        </div>
        <div class="span4">
          <button class="btn stop" id="toggle-btn">start upload</button>
        </div>
      </div>

      <hr />
    </div>
  </body>

  <script src="https://cdn.jsdelivr.net/npm/tus-js-client@2.3.2/dist/tus.js" crossorigin="anonymous"></script>
</html>
              
            
!

CSS

              
                body {
  padding-top: 40px;
}

.progress {
  height: 32px;
}

a.btn {
  margin-bottom: 2px;
}
              
            
!

JS

              
                /* global tus */
/* eslint-disable no-console, no-alert */

'use strict'

let upload = null
let uploadIsRunning = false
const toggleBtn = document.querySelector('#toggle-btn')
const input = document.querySelector('input[type=file]')
const progress = document.querySelector('.progress')
const progressBar = progress.querySelector('.bar')
const alertBox = document.querySelector('#support-alert')
const uploadList = document.querySelector('#upload-list')
const chunkInput = document.querySelector('#chunksize')
const tokenInput = document.querySelector('#token')
const videoidInput = document.querySelector('#video_id')
const clientidInput = document.querySelector('#client_id')
const parallelInput = document.querySelector('#paralleluploads')
const endpointInput = document.querySelector('#endpoint')

function reset() {
  input.value = ''
  toggleBtn.textContent = 'start upload'
  upload = null
  uploadIsRunning = false
}

function askToResumeUpload(previousUploads, currentUpload) {
  if (previousUploads.length === 0) return

  let text = 'You tried to upload this file previously at these times:\n\n'
  previousUploads.forEach((previousUpload, index) => {
    text += `[${index}] ${previousUpload.creationTime}\n`
  })
  text +=
    '\nEnter the corresponding number to resume an upload or press Cancel to start a new upload'

  const answer = prompt(text)
  const index = parseInt(answer, 10)

  if (!Number.isNaN(index) && previousUploads[index]) {
    currentUpload.resumeFromPreviousUpload(previousUploads[index])
  }
}

function startUpload() {
  const file = input.files[0]
  // Only continue if a file has actually been selected.
  // IE will trigger a change event even if we reset the input element
  // using reset() and we do not want to blow up later.
  if (!file) {
    return
  }

  const endpoint = endpointInput.value
  let chunkSize = parseInt(chunkInput.value, 10)
  if (Number.isNaN(chunkSize)) {
    chunkSize = Infinity
  }

  let parallelUploads = parseInt(parallelInput.value, 10)
  if (Number.isNaN(parallelUploads)) {
    parallelUploads = 1
  }

  const token = tokenInput.value

  let videoid = parseInt(videoidInput.value, 10)
  if (Number.isNaN(videoid)) {
    videoid = Infinity
  }

  let clientid = parseInt(clientidInput.value, 10)
  if (Number.isNaN(clientid)) {
    clientid = Infinity
  }

  toggleBtn.textContent = 'pause upload'

  const options = {
    endpoint,
    chunkSize,  //chunkSize: 100000000, // 100 MB
    retryDelays: [0, 1000, 3000], //, 5000, 10000, 20000],
    parallelUploads,
    //removeFingerprintOnSuccess: true,
    //storeFingerprintForResuming: false,
    metadata: {
      filename: file.name,
      filetype: file.type,
      // must provide these 3 fields
      token: token,
      video_id: videoid,
      client_id: clientid,
    },
    onError(error) {
      if (error.originalRequest) {
        console.log(`Failed because: ${error}`)
        if (window.confirm(`Failed because: ${error}\nDo you want to retry?`)) {
          upload.start()
          uploadIsRunning = true
          return
        }
      } else {
        window.alert(`Failed because: ${error}`)
      }

      reset()
    },
    onProgress(bytesUploaded, bytesTotal) {
      const percentage = ((bytesUploaded / bytesTotal) * 100).toFixed(2)
      progressBar.style.width = `${percentage}%`
      console.log(bytesUploaded, bytesTotal, `${percentage}%`)
    },
    onShouldRetry: function (err, retryAttempt, options) {
      // tus-js-client should retry
      console.log(`Failed because: ${err}\nRetry ${retryAttempt}`)
      return true
    },
    onSuccess() {
      console.log(`File ${upload.file.name} (${upload.file.type}, ${upload.file.size} bytes) is uploaded`)
      
      reset()
    },
  }

  upload = new tus.Upload(file, options)
  upload.findPreviousUploads().then((previousUploads) => {
    askToResumeUpload(previousUploads, upload)

    upload.start()
    uploadIsRunning = true
  })
}

if (!tus.isSupported) {
  alertBox.classList.remove('hidden')
}

if (!toggleBtn) {
  throw new Error('Toggle button not found on this page. Aborting upload-demo. ')
}

toggleBtn.addEventListener('click', (e) => {
  e.preventDefault()

  if (upload) {
    if (uploadIsRunning) {
      upload.abort()
      toggleBtn.textContent = 'resume upload'
      uploadIsRunning = false
    } else {
      upload.start()
      toggleBtn.textContent = 'pause upload'
      uploadIsRunning = true
    }
  } else if (input.files.length > 0) {
    startUpload()
  } else {
    input.click()
  }
})

input.addEventListener('change', startUpload)
              
            
!
999px

Console