uploading a recorded file via multipart form http request.

This commit is contained in:
Naomi 2011-03-06 16:45:11 -05:00
parent 6d792c0ca5
commit b4207698c3
7 changed files with 57 additions and 25 deletions

Binary file not shown.

View file

@ -1,8 +1,9 @@
# Hostname
base_url = 'http://campcaster.dev/'
# URL to get the version number of the server API
show_schedule_url = 'Recorder/get-show-schedule/format/json'
upload_file_url = 'Plupload/upload-recorded/format/json'
# base path to store recordered shows at
base_recorded_files = '/home/naomi/Music/'

View file

@ -107,12 +107,37 @@ def get_shows():
process_shows(shows)
check_record()
def upload_file():
from poster.encode import multipart_encode
from poster.streaminghttp import register_openers
import urllib2
# Register the streaming http handlers with urllib2
register_openers()
# Start the multipart/form-data encoding of the file "DSC0001.jpg"
# "image1" is the name of the parameter, which is normally set
# via the "name" parameter of the HTML <input> tag.
# headers contains the necessary Content-Type and Content-Length
# datagen is a generator object that yields the encoded parameters
datagen, headers = multipart_encode({"file": open("/home/naomi/Music/testoutput.mp3", "rb"), 'name': 'crazy.mp3'})
url = config["base_url"] + config["upload_file_url"]
req = urllib2.Request(url, datagen, headers)
response = urllib2.urlopen(req).read().strip()
print response
if __name__ == '__main__':
while True:
get_shows()
time.sleep(30)
# while True:
# get_shows()
# time.sleep(30)
upload_file()