파일 (이 경우 오디오/mp3)을 App Engine blobstore에 저장하려하지만 성공했습니다. 모든 것이 제대로 작동하는 것으로 보입니다. 파일은 올바른 유형의 blobstore에 저장되지만 본질적으로 비어 있습니다 (1.5kB 대 예상 6.5kB). 따라서 재생되지 않습니다. 문제의 URL은 http://translate.google.com/translate_tts?ie=UTF-8&tl=en&q=revenues+in+new+york+were+56+millionURL에서 오디오/mp3 파일 가져 오기 및 blobstore에 저장
입니다. 앱 엔진 로그에는 이상한 부분이 표시되지 않습니다. 모든 부분이 예상대로 실행되고 있습니다 ... 어떤 포인터라도 감사 할 것입니다!
class Dictation(webapp2.RequestHandler):
def post(self):
sentence = self.request.get('words')
# Google Translate API cannot handle strings > 100 characters
sentence = sentence[:100]
# Replace the non-alphanumeric characters
# The spaces in the sentence are replaced with the Plus symbol
sentence = urllib.urlencode({'q': sentence})
# Name of the MP3 file generated using the MD5 hash
mp3_file = hashlib.md5(sentence).hexdigest()
# Save the MP3 file in this folder with the .mp3 extension
mp3_file = mp3_file + ".mp3"
# Create the full URL
url = 'http://translate.google.com/translate_tts?ie=UTF-8&tl=en&' + sentence
# upload to blobstore
mp3_file = files.blobstore.create(mime_type = 'audio/mp3', _blobinfo_uploaded_filename = mp3_file)
mp3 = urllib.urlopen(url).read()
with files.open(mp3_file, 'a') as f:
f.write(mp3)
files.finalize(mp3_file)
blob_key = files.blobstore.get_blob_key(mp3_file)
logging.info('blob_key identified as %s', blob_key)