I’m trying to translate this working Python 3.x code, that uses Python’s “requests” library, into Javascript ES6 code that uses 'fetch", but I cannot seem to replicate the request using Javascript. The problem seems to be that the requests “files” parameter does some kind of form encoding. Anyone have ideas?
import json
import requests
url="https://something.com/dosomething"
something ="1"
headers = {
'Bearer': 'mysecretkey'
}
params = {
"type": "G",
"numImages": 1,
"generateParams": {
"query": "a query here"
}
}
data = {
'mode': (None, something),
'params': (None, json.dumps(params), 'application/json')
}
response = requests.post(url, headers, files=data)