Skip to content
+

FileWithPath

The FileWithPath object replaces the File object returned from file input controls and drop targets.

Usage

File Input Control

import { FileWithPath } from "@stoked-ui/media-selector";

const input = document.getElementById('myInput');
input.addEventListener('change', async evt => {
  const files = await FileWithPath.from(evt);
  console.log(files);
});

React Component

import React, { useState } from 'react';
import { FileWithPath } from "@stoked-ui/media-selector";

const FileComponent = () => {
  const [files, setFiles] = useState(null);
  const [fileName, setFileName] = useState('')

  const handleChange = (event) => {
    const newFiles = FileWithPath(event);
    if(newFiles.length) {
      const updatedFiles = [...files, ...newFiles];
      setFiles(updatedFiles);
      const name = Array.from(updatedFiles) .map((f) => { return f.name; }) .join(", ");
      setFileName(name);
    }
  }

  return (
    <div>
      <input type="file" onChange={handleChange} />
      <label class="custom-file-label" for="customFile">{fileName || 'Choose File' }</label>
    </div>
  )
}

What's next

  • Check the Media Selector Roadmap (soon) to see what's coming next for this library.
  • Check the Video Editor Roadmap to see the larger context.