fix multipart example

pull/428/head
Lucas Nogueira 2 years ago
parent 4bc57234f5
commit 4d77e65314
No known key found for this signature in database
GPG Key ID: FFEA6C72E73482F1

@ -34,9 +34,12 @@
const response = await tauriFetch("http://localhost:3003", options); const response = await tauriFetch("http://localhost:3003", options);
const body = const body =
bodyType === "json" ? await response.json() : await response.text(); bodyType === "json" ? await response.json() : await response.text();
onMessage({ onMessage({
url: response.url, url: response.url,
status: response.status, status: response.status,
ok: response.ok,
headers: Object.fromEntries(response.headers.entries()),
body, body,
}); });
} }
@ -45,23 +48,20 @@
let foo = "baz"; let foo = "baz";
let bar = "qux"; let bar = "qux";
let result = null; let result = null;
let multipart = true;
async function doPost() { async function doPost() {
const form = new FormData();
form.append("foo", foo);
form.append("bar", bar);
const response = await tauriFetch("http://localhost:3003", { const response = await tauriFetch("http://localhost:3003", {
method: "POST", method: "POST",
body: { body: form,
foo,
bar,
},
headers: multipart
? { "Content-Type": "multipart/form-data" }
: undefined,
}); });
result = { result = {
url: response.url, url: response.url,
status: response.status, status: response.status,
headers: JSON.parse(JSON.stringify(response.headers)), ok: response.ok,
headers: Object.fromEntries(response.headers.entries()),
body: await response.text(), body: await response.text(),
}; };
} }
@ -96,11 +96,6 @@
<input class="input" bind:value={bar} /> <input class="input" bind:value={bar} />
</div> </div>
<br /> <br />
<label>
<input type="checkbox" bind:checked={multipart} />
Multipart
</label>
<br />
<br /> <br />
<button class="btn" type="button" on:click={doPost}> Post it</button> <button class="btn" type="button" on:click={doPost}> Post it</button>
<br /> <br />

Loading…
Cancel
Save