How to use the ember-file-upload/system/file-reader function in ember-file-upload

To help you get started, we’ve selected a few ember-file-upload examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github adopted-ember-addons / ember-file-upload / addon / mirage / utils.js View on Github external
gif(file) {
    let reader = new FileReader();
    return reader.readAsArrayBuffer(file).then(function (buffer) {
      let data = new Uint8Array(buffer);
      let duration = 0;
      for (let i = 0; i < data.length; i++) {
        // Find a Graphic Control Extension hex(21F904__ ____ __00)
        if (data[i] === 0x21 &&
            data[i + 1] === 0xF9 &&
            data[i + 2] === 0x04 &&
            data[i + 7] === 0x00) {
          // Swap 5th and 6th bytes to get the delay per frame
          let delay = (data[i + 5] << 8) | (data[i + 4] & 0xFF);

          // Should be aware browsers have a minimum frame delay
          // e.g. 6ms for IE, 2ms modern browsers (50fps)
          duration += delay < 2 ? 10 : delay;
        }
github adopted-ember-addons / ember-file-upload / addon / mirage / utils.js View on Github external
export function extractFileMetadata(file) {
  let metadata = {
    name: file.name,
    size: file.size,
    type: file.type,
    extension: (file.name.match(/\.(.*)$/) || [])[1]
  };

  let reader = new FileReader();
  return reader.readAsDataURL(file).then(function (url) {
    metadata.url = url;

    let additionalMetadata = [];

    if (metadata.type === 'image/gif') {
      additionalMetadata.push(pipelines.gif(file, metadata));
    }
    if (metadata.type.match(/^image\//)) {
      additionalMetadata.push(pipelines.image(file, metadata));
    }
    if (metadata.type.match(/^video\//)) {
      additionalMetadata.push(pipelines.video(file, metadata));
    }
    if (metadata.type.match(/^audio\//)) {
      additionalMetadata.push(pipelines.audio(file, metadata));