observablehq / feedback

Customer submitted bugs and feature requests
42 stars 3 forks source link

Expose FileAttachment Metadata for Observable Notebooks #496

Open MarioDelgadoSr opened 1 year ago

MarioDelgadoSr commented 1 year ago

Feature Request: Data-driven artifacts in notebooks today can't utilize FileAttachments metadata (uploaded date/time, size, type, EXIF metadata (for pictures if it exists) as part the notebook content exposed to a user.

Solution: Enhance the FileAttachment object with attributes exposing relevant metadata.

Alternatives: An alternative is using a naming convention for the file attached that will then be parsed at run-time from the file's name. The downside to this is that several versions of a file will be uploaded with unique names, rather than the convenient versioning naming scheme currently used when replacing an uploaded FileAttachment. In addition, code will have to be altered to reference the new/parsed filename.

mythmon commented 1 year ago

Metadata support would be nice. However, some of this information is already available:

In the below code, fa = await FileAttachment("file.png")

/// cell 1
exif = require('exif-js@2.3.0/exif.js')
// cell 2
imageMetadata = {
  let fa = await FileAttachment("Canon_40D.jpg");
  let image = await fa.image();
  return new Promise((resolve) => {
    exif.getData(image, function () {
      resolve(exif.getAllTags(this));
    });
  });
}

Also accessible (via the blob interface) is the last modified date, though this seems unrelated to upload date. As far as I can tell the upload time and date remain inaccessible.