ULB-Darmstadt / shacl-form

HTML5 web component for editing/viewing RDF data that conform to SHACL shapes
https://ulb-darmstadt.github.io/shacl-form/
MIT License
24 stars 4 forks source link

Feature request: image ( file ) upload #8

Closed thhck closed 4 months ago

thhck commented 5 months ago

Hi ,

It would be a great to be able to upload a file.

However I'm not sure how to implement it.

In javascript, <input type="file"..> return directly a File object. This won't be possible with shacl-form, but maybe the form can return some primitive that allow to create the javascript file object afterward ?

s-tittel commented 5 months ago

Hi, there are a couple of options for that:

  1. Version 1.4.1 now supports the datatype xsd:base64Binary and renders an <input type="file"> element for that. So if you define a SHACL property with that datatype in the shapes graph, you will get the base64 encoded data URL in the data graph. I have tested that successfully with files up to ~500 kB, larger files will lead to an error during validation due to too much recursion (within the library that I use for that).
  2. Create a plugin for that. You could register your plugin for the RDF predicate that you use in your shapes graph for the file. Your plugin could then handle the file upload itself in any way you prefer.
  3. Modify the form with JavaScript at runtime, basically inserting an <input type="file"> element at the position you desire.
s-tittel commented 4 months ago

Plugin has been merged