你不能修改GCS中的文件。一旦他們關閉了多數民衆贊成它。要追加我這樣做:
import cloudstorage
from google.appengine.api import app_identity
bucketName = app_identity.get_default_gcs_bucket_name()
class MainPage(webapp2.RequestHandler):
def get(self):
fileName = "/" + bucketName + "/somedir/somefile.txt"
try:
with cloudstorage.open(fileName, "r") as gcsFile:
tempStorage = gcsFile.read()
tempStorage += "\n"
except:
tempStorage = ""
with cloudstorage.open(fileName, "w") as gcsFile:
gcsFile.write(tempStorage + "appended text")
with cloudstorage.open(fileName, "r") as gcsFile:
output= gcsFile.read()
self.response.out.write(output)
只是寫:
import cloudstorage
from google.appengine.api import app_identity
bucketName = app_identity.get_default_gcs_bucket_name()
fileName = "/" + bucketName + "/somedir/somefile.txt"
with cloudstorage.open(fileName, "w") as gcsFile:
gcsFile.write("text")