System Information
- Strapi Version: 4.0
- Operating System: Windows
- Database: PG
- Node Version:
- NPM Version:
- Yarn Version:
on the Upload documentation here: Upload - Strapi Developer Docs
The docs give a code snippet for uploading a binary file in JavaScript.
<script type="text/javascript">
const formElement = document.querySelector('form');
formElement.addEventListener('submit', (e) => {
e.preventDefault();
const request = new XMLHttpRequest();
request.open('POST', '/upload');
request.send(new FormData(formElement));
});
</script>
How do I do it in Python?
This is what I have so far:
url = f"{strapi_server_url}/api/upload"
headers = {
'Authorization': f"Bearer {jwt}",
}
file = open(os.getcwd() + f'\\{filename}.stl', 'rb')
data = file.read()
print(f"LENGTH FILE: {len(data)}")
response = requests.post(url, files={'file': data}, headers=headers)
I get the error “Files are empty” But I know that the data variable has a length of 5 MB.