ошибка 500: ApiError при попытке загрузить файл в GCS с помощью GAE Flexible - PullRequest
0 голосов
/ 04 октября 2018

Я пытаюсь сделать API, развернутый с Google App Engine, гибким, который загружает файлы в Google Storage.Когда я запускаю API с localhost, он работает довольно хорошо.Но с развернутым приложением я получаю эту ошибку:

ApiError: Error during request.
at Object.parseHttpRespBody (/srv/node_modules/@google-cloud/common/src/util.js:187:32)
at Object.handleResp (/srv/node_modules/@google-cloud/common/src/util.js:131:18)

Я предоставил разрешение администратора хранилища учетной записи службы, но также и ту же ошибку.

export function toStorage(request: Request, response: Response, next: NextFunction) {
  const storage = Storage({
    projectId: process.env.GCLOUD_PROJECT
  })
  // A bucket is a container for objects (files).
  const bucket = storage.bucket(process.env.OUTPUT)
  console.log(process.env.GCLOUD_PROJECT)
  console.log(process.env.OUTPUT)
  if (!request.file) {
    response.status(400).send('No file uploaded.')
    return
  }

  // Create a new blob in the bucket and upload the file data.
  const blob = bucket.file(request.file.originalname)
  const blobStream = blob.createWriteStream({
    resumable: false
  })

  blobStream.on('error', (err: Error) => {
    next(err)
  })

  blobStream.on('finish', () => {
    // The public URL can be used to directly access the file via HTTP.
    const publicUrl = format(`https://storage.googleapis.com/${bucket.name}/${blob.name}`)
    sendResponse(response, publicUrl)
  })

  blobStream.end(request.file.buffer)

}

Заранее спасибоподдержка помощь.

...