Last active
August 29, 2015 14:26
-
-
Save ryanchang/0ead8f7efd274ecbf0e0 to your computer and use it in GitHub Desktop.
Upload audio file to rails server with paperclip with python requests HTTP client.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import base64 | |
from datetime import datetime | |
import json | |
f = open('output.mp3') | |
recording = base64.b64encode(f.read()) | |
current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') | |
payload = {'audio_clip': {'device':'0005', 'time':current_time, 'recording':{'filename':'output.mp3', 'content_type':'audio/mp3', 'content':recording}}} | |
headers = {'content-type':'application/json'} | |
response = requests.post('http://localhost:7000/api/audio_clips', data=json.dumps(payload), headers=headers) | |
print response.text | |
print response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment