# Resumable Upload

A simulated file transfer can pause and continue from the same progress.

## Try it

Start the transfer, pause partway through, and resume. Cancel a transfer to try it again from the beginning.

## Interaction details

Simulate sending an 8 MB print file locally over about six seconds. Pause freezes the progress bar. Resume sends the remaining portion, while retry after cancellation starts at zero.

## Platform controls

- iOS · Tap to start the file transfer. Pause it, then resume and watch progress continue from that point.
- Android · Tap to start the file transfer. Pause it, then resume and watch progress continue from that point.
- PC · Tab to the transfer control and use Enter to start, pause, or resume.

## Where to use it

Submitting print files, uploading media, or tracking a lengthy transfer.

## Implementation prompt

> Show progress and distinguish pause, resume, cancel, restart, and completion.

## Sources and credits

[Firebase · Upload files on the web](<https://firebase.google.com/docs/storage/web/upload-files>)

## Standalone HTML

Save the code below as an HTML file and open it in your browser. The example works offline.

```html
<!doctype html>
<html lang="en"><head><script>if(new URLSearchParams(location.search).get('reduce')==='1')document.documentElement.classList.add('motion-reduced');</script><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Send Print File</title>
<style>
*{box-sizing:border-box}body{margin:0;background:#e7dfde;color:#221620;font:15px/1.48 system-ui,sans-serif;min-height:100vh;display:grid;align-items:center}main{width:min(720px,100%);margin:auto;padding:clamp(16px,4%,38px)}.console{background:#392537;color:#fff7ed;box-shadow:0 14px 35px #301d2f24;padding:clamp(20px,5%,38px);border-radius:4px}.top,.file,.stats,.actions{display:flex;align-items:center;justify-content:space-between;gap:12px}.top{padding-bottom:17px;border-bottom:1px solid #826a7e}.top h1{font-size:clamp(19px,3em,28px);margin:0;letter-spacing:-.06em}.local{font-size:12px;color:#dfc9d9;white-space:nowrap}.file{margin:24px 0;justify-content:flex-start}.thumb{width:76px;height:90px;flex:none;overflow:hidden;position:relative;background:#f2d593;color:#603246;box-shadow:3px 4px 0 #261826}.thumb:before{content:'';position:absolute;inset:-27px -28px 12px 12px;background:repeating-radial-gradient(ellipse at 58% 45%,#713a55 0 4px,transparent 5px 9px);transform:rotate(-22deg)}.thumb small{position:absolute;bottom:2px;left:5px;letter-spacing:.13em;font:700 9px/1.3 monospace}.file h2{font:italic 400 clamp(26px,4vw,39px)/1.1 Georgia,serif;letter-spacing:-.05em;margin:0 0 6px}.file p,.status{margin:0;color:#e1d3d9;font-size:13px}.stats{align-items:baseline}.stats strong{font:400 clamp(32px,5vw,48px)/1 Georgia,serif;letter-spacing:-.05em}.capacity{font:12px/1.4 ui-monospace,Consolas,monospace;color:#f6dd9d}.bar{height:14px;overflow:hidden;background:#61485d;border-radius:1px;margin:10px 0 7px}.fill{display:block;height:100%;width:0;background:repeating-linear-gradient(110deg,#f4d896 0 7px,#d6b46c 7px 9px);transition:width .14s linear}.actions{margin-top:19px;justify-content:flex-start;flex-wrap:wrap}.actions button{border:1px solid #b69aaf;background:transparent;color:inherit;min-height:44px;padding:8px 17px;border-radius:2px;font-family:inherit;font-size:14px;font-weight:650;cursor:pointer}.actions #action{background:#f4d896;color:#332036;border-color:#f4d896}.actions button:disabled{opacity:.43;cursor:default}button:focus-visible{outline:3px solid #fff;outline-offset:3px}.motion-reduced .fill{transition:none}@media(prefers-reduced-motion:reduce){.fill{transition:none}}
</style></head><body><main><section class="console" aria-labelledby="title"><header class="top"><h1 id="title">Send Print File</h1><span class="local">Local simulation</span></header>
<div class="file"><div class="thumb" aria-hidden="true"><small>VIOLET / 03</small></div><div><h2>Violet Riso</h2><p>violet-riso.pdf · 8 MB</p></div></div>
<div class="stats"><strong id="percent">0%</strong><span class="capacity" id="amount">0.0 / 8 MB</span></div><div id="meter" class="bar" role="progressbar" aria-label="Print file transfer progress" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><span class="fill"></span></div>
<p id="status" class="status" role="status">Ready to send</p><div class="actions"><button type="button" id="action">Start transfer</button><button type="button" id="cancel" disabled>Cancel transfer</button></div></section></main>
<script>
(()=>{
  const get=id=>document.getElementById(id);
  const action=get('action'), cancel=get('cancel'), fill=document.querySelector('.fill');
  let state='ready', elapsed=0, start=0, timer=0;
  const duration=6000;
  function paint(ms) {
    const p=Math.min(100,Math.floor(ms/duration*100));
    fill.style.width=p+'%';
    get('meter').setAttribute('aria-valuenow',p);
    get('percent').textContent=p+'%';
    get('amount').textContent=(p*.08).toFixed(1)+' / 8 MB';
  }
  function setState(next) {
    state=next;
    const labels={ready:['Ready to send','Start transfer'],running:['Sending to the print studio','Pause'],paused:['Transfer paused.','Resume'],cancelled:['Transfer canceled.','Send from beginning'],complete:['8 MB transferred','Send again']};
    get('status').textContent=labels[state][0];
    action.textContent=labels[state][1];
    cancel.disabled=state!=='running'&&state!=='paused';
  }
  function tick() {
    const now=Math.min(duration,elapsed+performance.now()-start);
    paint(now);
    if(now===duration){clearInterval(timer);elapsed=duration;setState('complete');}
  }
  action.addEventListener('click',()=>{
    if(state==='running'){
      tick();
      if(state==='complete')return;
      elapsed=Math.min(duration,elapsed+performance.now()-start);
      clearInterval(timer);setState('paused');return;
    }
    if(state!=='paused'){elapsed=0;paint(0);}
    start=performance.now();setState('running');timer=setInterval(tick,90);
  });
  cancel.addEventListener('click',()=>{
    clearInterval(timer);elapsed=0;paint(0);setState('cancelled');action.focus();
  });
  addEventListener('pagehide',()=>{if(state==='running')action.click();});
})();
</script></body></html>
```
