我在google appengine上有一个应用程序,并将我的文件存储在google cloudstorage中。 这是代码:
import os
import cloudstorage as gcs
from google.appengine.api import app_identity
from settings import BUCKET_NAME
uploaded_file = self.request.POST.get("file")
uploaded_file_content = uploaded_file.file.read()
uploaded_file_filename = uploaded_file.filename
uploaded_file_type = uploaded_file.type
# This write_retry_params params bit isn't essential, but Google's examples recommend it
write_retry_params = gcs.RetryParams(backoff_factor=1.1)
gcs_file = gcs.open(
"/" + BUCKET_NAME + "/" + uploaded_file_filename,
"w",
content_type=uploaded_file_type,
retry_params=write_retry_params
)
gcs_file.write(uploaded_file_content)
gcs_file.close()
此代码有效,文件不会显示在存储桶中,我也不知道公众网址是否存在以检查文件是否存在。