TheSpyder / rescript-webapi

ReScript bindings to the DOM and other Web APIs
http://tinymce.github.io/rescript-webapi/api/Webapi/
Other
149 stars 36 forks source link

Unable to pass Webapi.Blob.t to Webapi.Url.createObjectUrl #100

Closed Minnozz closed 2 years ago

Minnozz commented 2 years ago

Webapi.Url.createObjectUrl accepts a Webapi.File.t. This is a "superclass" of Webapi.Blob.t, but because createObjectUrl is not a method of File, it is not generated for Blob too.

spocke commented 2 years ago

I wounder what the best approach to this one would be since there are many routes we could take and we have now kind of a mixed bag of these approaches.

  1. Use two bindings/functions one for blob -> string one for file -> string.
  2. Use polymorphic types and @unwrap just one function but multiple types though the variants.
  3. Use a separate opaque type that you convert blob and file into first.
  4. Have separate submodules to Url one for File and one for Blob each having a createObjectUrl (kind of similar to 1).

Personally I think 1 and 2 would be best for this particular binding.

LeoLeBras commented 2 years ago

I had to deal with this same issue recently @Minnozz. This is how I solved it:

open Webapi
let blob = ...
let filename = "..."
let objectUrl = Url.createObjectURL(File.make([blob->Blob.blobToBlobPart], filename))