and replace using axios, return this error: has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
const media = new FormData();
media.append('media', fs.createReadStream(path));
let config = {
method: 'post',
maxBodyLength: Infinity,
url: url,
headers: {
...this.getHeaders()
},
data : media
};
const res = await axios.request(config)
console.log(res);
this is requests.request python package encode multipart_formdata func
def encode_multipart_formdata(fields, boundary=None):
"""
Encode a dictionary of ``fields`` using the multipart/form-data MIME format.
:param fields:
Dictionary of fields or list of (key, :class:`~urllib3.fields.RequestField`).
:param boundary:
If not specified, then a random boundary will be generated using
:func:`urllib3.filepost.choose_boundary`.
"""
body = BytesIO()
if boundary is None:
boundary = choose_boundary()
for field in iter_field_objects(fields):
body.write(b("--%s\r\n" % (boundary)))
writer(body).write(field.render_headers())
data = field.data
if isinstance(data, int):
data = str(data) # Backwards compatibility
if isinstance(data, six.text_type):
writer(body).write(data)
else:
body.write(data)
body.write(b"\r\n")
body.write(b("--%s--\r\n" % (boundary)))
content_type = str("multipart/form-data; boundary=%s" % boundary)
return body.getvalue(), content_type