How to write raw bytes to Google cloud storage with GAE's Python API

后端 未结 1 999
野性不改
野性不改 2021-01-05 11:51

I am trying to modify some binary data submitted by user form, and write it to Google Cloud Storage. I tried to follow Google document\'s example, but upon writing I got er

相关标签:
1条回答
  • 2021-01-05 12:41

    I suppose the problem is that gcs_file.write() method expects data of type "str". Since type of your buf is "unicode" and apparently contains some Unicode chars (maybe in ID3 tags), you get UnicodeDecodeError. So you just need to encode buf to UTF-8:

    gcs_file = gcs.open(filename,'w',content_type='audio/mp3')
    gcs_file.write(buf.encode('utf-8'))
    gcs_file.close()
    
    0 讨论(0)
提交回复
热议问题