I'm trying to post a request using FormData(), I need to include the "content type" header so I'm using the blob to append entries to my form, but this automatically sets the filename to "blob"
const formData = new FormData();
const obj1 = new Blob([json_data], {type: 'text/plain; encoding=utf-8'});
formData.append("small_config", obj1);
const obj2 = new Blob([client], {type: 'text/plain; encoding=utf-8'});
formData.append("app_type", obj2);
const obj3 = new Blob([version], {type: 'text/plain; encoding=utf-8'});
formData.append("product_version", obj3);
let thumb = await fetch(my_url, {
method: 'POST',
mode: 'cors',
cache: 'no-cache',
credentials: 'same-origin',
redirect: 'follow',
referrerPolicy: 'no-referrer',
body: formData
});
Is there a way to both set the content type and not include filename?
There is no way to have FormData not send a filename with an appended blob. You can send an empty string however.
Use the 3rd parameter to FormData.append
formData.append("small_config", obj1, 'My Filename');
So for your case, try an empty string.
formData.append("small_config", obj1, '');
From Mozilla docs:
filename Optional
The filename reported to the server (a USVString), when a Blob or File is passed as the second parameter. The default filename for Blob objects is "blob". The default filename for File objects is the file's filename.