noellarkin
Senior Member
- Mar 14, 2021
- 1,006
- 1,492
For some reason, the answer to this has been impossible for me to find on StackOverflow.
I want to upload a local file to an API.
The file is located at C:\samplefolder\samplefile.wav
The API documentation tells me to upload it like this:
Here's the part I don't get. filename = "/path/to/foo.wav" is how every single file upload example on the internet seems to do it. But filename = "C:\samplefolder\samplefile.wav" doesn't seem to work.
How do I upload a local file from my hard drive, and why is it so effin' hard to find an example of this on the internet?
I want to upload a local file to an API.
The file is located at C:\samplefolder\samplefile.wav
The API documentation tells me to upload it like this:
Python:
import requests
filename = "/path/to/foo.wav"
def read_file(filename, chunk_size=5242880):
with open(filename, 'rb') as _file:
while True:
data = _file.read(chunk_size)
if not data:
break
yield data
headers = {'authorization': "YOUR-API-TOKEN"}
response = requests.post('https://api.assemblyai.com/v2/upload',
headers=headers,
data=read_file(filename))
print(response.json())
Here's the part I don't get. filename = "/path/to/foo.wav" is how every single file upload example on the internet seems to do it. But filename = "C:\samplefolder\samplefile.wav" doesn't seem to work.
How do I upload a local file from my hard drive, and why is it so effin' hard to find an example of this on the internet?