wailsapp / wails

Create beautiful applications using Go
https://wails.io
MIT License
25.25k stars 1.21k forks source link

How can I receive a File or Blob instance from frontend ? #3230

Open LXG19961206 opened 9 months ago

LXG19961206 commented 9 months ago

Is your feature request related to a problem? Please describe.

a simple code example here...

// js let blob = new Blob(["hello world"], {type: "text/plain;charset=utf-8"});
await ReceiveBlob(blob)

// wails go func (rec *app) (blob any) ReceiveBlob { ... // when I can this function, I got map[string]interface{}, and the map has no key , how can i receive it as a blob instance }

Describe the solution you'd like

please help me

Describe alternatives you've considered

No response

Additional context

No response

leaanthony commented 9 months ago

Thanks for opening this. What are you really trying to achieve with this? Sending a file from JS counter-intuitive for a Go program. There's probably a better way of doing it.

LXG19961206 commented 9 months ago

Thanks for opening this. What are you really trying to achieve with this? Sending a file from JS counter-intuitive for a Go program. There's probably a better way of doing it.

My business needs to use HTMLCanvas to dynamically draw data, then convert it into images and hand it over to the Wails Golang process, Unable to directly call native functions of wails

mjiulee commented 7 months ago

cover to base64 data as string ,then send to go.

mateothegreat commented 5 months ago

The signature blob any is why you're getting map[string]interface{}.

You need to serialize your data and then send it to wails like:

async function greet() {
  let blob = new Blob(["hello world"], { type: "text/plain;charset=utf-8" });
  // base64 encoded result:
  const result = btoa(await blob.text());

  Greet(result).then((result) => {
    greeting = result;
  });
}
func (a *App) Greet(blob string) string {
...
}

CleanShot 2024-05-18 at 00 46 41