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

user2686101

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 errors such as:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 34: ordinal not in range.

My code is simply as below

gcs_file = gcs.open(filename,'w',content_type='audio/mp3')
gcs_file.write(buf)
gcs_file.close()

I tried to open file with 'wb' mode but got a "Invalid mode wb." error.

I found a similar question at GCS's maillist which was on Java. There the GCS develop team's suggest was to use writeChannel.write() instead of PrintWriter. Could anybody suggest how to make it work in Python?

Denisigo

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()

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to upload video through Python GAE to Google Cloud Storage?

From Dev

GAE Python + Google Cloud Storage authorization problems

From Dev

GAE Python unable to write file properly to Cloud Storage

From Dev

How can I run local unit tests on models that use Google Cloud Storage on GAE (python)

From Java

Write to Google Cloud Storage from Cloud Function (python)

From Dev

Write to Google Cloud Storage from Cloud Function (python)

From Dev

Upload .raw files to Google Cloud Storage

From Dev

Difference between GAE Storage pricing and Google Cloud Storage pricing

From Dev

Difference between GAE Storage pricing and Google Cloud Storage pricing

From Dev

Only 14 bytes are uploaded into Google Cloud Storage

From Dev

How to append write to google cloud storage file from app engine?

From Dev

python and google cloud storage

From Dev

GAE - How to get last modified / renamed datetime of google cloud storage object from php

From Dev

How to install the python library - google-api-python-client-gae?

From Dev

Error in Generating API (Google Cloud Endpoint) with GAE

From Dev

How do I write compressed files to Google Cloud Storage using Google Cloud Dataflow?

From Dev

Uploading files directly to Google Cloud Storage for GAE app

From Dev

Uploading files directly to Google Cloud Storage for GAE app

From Dev

Cloud Storage API requests from GAE - 403 Access not configured

From Dev

How to rename or move a file in Google Cloud Storage (PHP API)

From Dev

How to read raw bytes from socket in Python?

From Dev

How to change the scope of a Google Compute Engine service account to write data to a Google Cloud Storage bucket?

From Dev

How to write tests for API based on Google Cloud Endpoints?

From Dev

How to upload a file to Google Cloud Storage on Python 3?

From Dev

how to store an image on Google Cloud Storage sent by Android using Python

From Dev

how to store an image on Google Cloud Storage sent by Android using Python

From Dev

How to upload a JSON to google cloud storage using python

From Dev

How do I write raw bytes to a sound-device?

From Dev

Google Cloud Storage - how to authorize?

Related Related

  1. 1

    How to upload video through Python GAE to Google Cloud Storage?

  2. 2

    GAE Python + Google Cloud Storage authorization problems

  3. 3

    GAE Python unable to write file properly to Cloud Storage

  4. 4

    How can I run local unit tests on models that use Google Cloud Storage on GAE (python)

  5. 5

    Write to Google Cloud Storage from Cloud Function (python)

  6. 6

    Write to Google Cloud Storage from Cloud Function (python)

  7. 7

    Upload .raw files to Google Cloud Storage

  8. 8

    Difference between GAE Storage pricing and Google Cloud Storage pricing

  9. 9

    Difference between GAE Storage pricing and Google Cloud Storage pricing

  10. 10

    Only 14 bytes are uploaded into Google Cloud Storage

  11. 11

    How to append write to google cloud storage file from app engine?

  12. 12

    python and google cloud storage

  13. 13

    GAE - How to get last modified / renamed datetime of google cloud storage object from php

  14. 14

    How to install the python library - google-api-python-client-gae?

  15. 15

    Error in Generating API (Google Cloud Endpoint) with GAE

  16. 16

    How do I write compressed files to Google Cloud Storage using Google Cloud Dataflow?

  17. 17

    Uploading files directly to Google Cloud Storage for GAE app

  18. 18

    Uploading files directly to Google Cloud Storage for GAE app

  19. 19

    Cloud Storage API requests from GAE - 403 Access not configured

  20. 20

    How to rename or move a file in Google Cloud Storage (PHP API)

  21. 21

    How to read raw bytes from socket in Python?

  22. 22

    How to change the scope of a Google Compute Engine service account to write data to a Google Cloud Storage bucket?

  23. 23

    How to write tests for API based on Google Cloud Endpoints?

  24. 24

    How to upload a file to Google Cloud Storage on Python 3?

  25. 25

    how to store an image on Google Cloud Storage sent by Android using Python

  26. 26

    how to store an image on Google Cloud Storage sent by Android using Python

  27. 27

    How to upload a JSON to google cloud storage using python

  28. 28

    How do I write raw bytes to a sound-device?

  29. 29

    Google Cloud Storage - how to authorize?

HotTag

Archive