uploading a recorded file via multipart form http request.
This commit is contained in:
parent
6d792c0ca5
commit
b4207698c3
7 changed files with 57 additions and 25 deletions
|
@ -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()
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue