Spent a little time trying to figure this one out but since I can’t seem to get the web inspector working to debug the webview context making it pretty hard to help you...
Personally, I wouldn’t use a webview. Seems like there are some changes Sketch has made to the app runtime that make downloading things via a webview much harder. While there is a steeper learning curve, the cocoa apis offer quite a bit of flexibility and make this quite a bit simpler.
That being said I think you are on the right track.
- You can use the
FileReader api to create a base64 representation.
- Send that over to the plugin js context via
- Convert that bas64 string to a
- Then write the data file to disc using