当我尝试从 blobstore 下载文件时遇到问题。我的应用程序将一些文件与 blobstore 中的数据合并以创建一个大文件 (50 MB)。这是我的代码:
fileName=""
def post(self):
cadenaSalida = []
for empiece in range(1):
cadenaSubsidio="ficheroCSV" + str(empiece)
logging.info(cadenaSubsidio)
gqlQuery = blobstore.BlobInfo.gql("WHERE filename=:1",cadenaSubsidio)
blobs = gqlQuery.fetch(1)
if blobs :
for doc in blobs :
logging.info(doc.key())
blob_reader = blobstore.BlobReader(doc.key())
cadenaSalida.append(blob_reader.readlines(None))
logging.info("DESPUES DE LEER TODO EL FICHERO")
else:
logging.info("NO HAY DOCUMENTOS")
logging.info("Creamos el fichero")
cadenaTotal="csvTotal.csv"
logging.info(cadenaTotal)
self.creartxt(cadenaTotal)
logging.info(self.fileName)
f=self.abrirtxt()
logging.info(f)
self.escribirtxt(f, cadenaSalida)
self.cerrartxt(f)
resource = str(urllib.unquote(self.fileName))
blob_info = blobstore.BlobInfo.get(resource)
self.send_blob(blob_info)
它分配的 self.fileName 的值:
def creartxt (self,nombreCSV):
# Create the file
self.fileName = files.blobstore.create(mime_type='application/octet-stream',_blobinfo_uploaded_filename=nombreCSV)
def abrirtxt (self):
f= files.open(self.fileName, 'a')
return f
我使用的其他方法是:
def escribirtxt(self,f, lineas):
logging.info("VAMOS A ESCRIBIR EL TXT")
for linea in lineas:
logging.info(linea)
try:
f.write(str(linea))
except:
logging.info("Da el punetero errror e intentamos abrir el fichero")
f= files.open(self.fileName, 'a')
logging.info("Antes de escribir")
f.write(linea)
logging.info("Despues de escribir")
def cerrartxt(self,f):
f.close()
files.finalize(self.fileName)
但是,出现错误:“BadValueError: name must be under 500 bytes.”。我怎样才能避免这个错误?
堆栈跟踪是:
抱歉,堆栈跟踪是:
name must be under 500 bytes.
Traceback (most recent call last):
File "/base/data/home/runtimes/python/python_lib/versions/1/google/appengine/ext/webapp/_webapp25.py", line 716, in __call__
handler.post(*groups)
File "/base/data/home/apps/s~ono-hat-vv2/1.369495673401411273/com/__init__.py", line 207, in post
blob_info = blobstore.BlobInfo.get(resource)
File "/base/data/home/runtimes/python/python_lib/versions/1/google/appengine/ext/blobstore/blobstore.py", line 300, in get
blob_keys = cls.__normalize_and_convert_keys(blob_keys)
File "/base/data/home/runtimes/python/python_lib/versions/1/google/appengine/ext/blobstore/blobstore.py", line 390, in __normalize_and_convert_keys
keys[index] = datastore.Key.from_path(cls.kind(), str(key), namespace='')
File "/base/data/home/runtimes/python/python_lib/versions/1/google/appengine/api/datastore_types.py", line 514, in from_path
ValidateString(id_or_name, 'name')
File "/base/data/home/runtimes/python/python_lib/versions/1/google/appengine/api/datastore_types.py", line 176, in ValidateString
raise exception('%s must be under %d bytes.' % (name, max_len))
BadValueError: name must be under 500 bytes.
错误发生在以下行:
blob_info = blobstore.BlobInfo.get(资源)
问候。