You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Deployment Manager在GCS存储桶创建文件夹遇400错误求助

Fixing GCS Folder Creation Error in Deployment Manager

Got it, let's break down why you're seeing that 400 error and how to resolve it.

Root Cause

When you try to create an object (even an empty folder) in GCS using the storage.v1.object resource in Deployment Manager, the default API endpoint doesn't support direct object uploads. The error message tells you exactly this: upload requests need to use the /upload/ path and include the uploadType parameter, which the standard storage.v1.object endpoint doesn't handle automatically.

Also, remember that in GCS, folders aren't actual entities—they're just zero-byte objects with names ending in a trailing slash (/). So to create a "folder", you need to create such an empty object.

Solution 1: Use Cloud Build with gsutil (Simpler Approach)

This is the most straightforward way to create folders in GCS via Deployment Manager. We'll use Cloud Build to run the gsutil mkdir command, which handles all the API endpoint details for you.

Here's the updated Deployment Manager config:

resources:
- type: storage.v1.bucket
  name: test-bucket
  properties:
    project: my-project
    name: test-bucket
- type: gcp-types/cloudbuild-v1:projects.builds
  name: create-test-folder
  properties:
    projectId: my-project
    steps:
    - name: gcr.io/google.com/cloudsdktool/cloud-sdk
      args: ["gsutil", "mkdir", "gs://test-bucket/test/"]
  metadata:
    dependsOn:
    - test-bucket  # Ensure the bucket exists before creating the folder

Why this works:

  • gsutil mkdir automatically creates the empty trailing-slash object needed for the folder.
  • Cloud Build runs the command in a serverless environment, so no need to manage VMs.
  • It handles the correct API endpoint and parameters under the hood.

Solution 2: Configure storage.v1.object for Upload

If you prefer to use the native storage.v1.object resource, you need to override the API URL to use the upload endpoint and send an empty payload.

Here's the corrected config:

resources:
- type: storage.v1.bucket
  name: test-bucket
  properties:
    project: my-project
    name: test-bucket
- type: storage.v1.object
  name: test-folder
  properties:
    project: my-project
    bucket: test-bucket
    name: test/  # Trailing slash is required for folder visualization
  url: https://www.googleapis.com/upload/storage/v1/b/test-bucket/o?uploadType=media
  data: ""  # Empty payload for the folder object
  metadata:
    dependsOn:
    - test-bucket

Key Fixes:

  1. url: Points to the upload-specific endpoint with uploadType=media (required for uploading objects, including empty ones).
  2. name: Ends with / so GCS recognizes it as a folder.
  3. data: Empty string to create the zero-byte object.

Bonus Note

You don't actually need to create folders in GCS to upload files into them. If you upload an object named test/file.txt, the test/ folder will automatically appear in the GCS console. Creating the folder explicitly is only necessary if you want it to exist without any files inside.

内容的提问来源于stack exchange,提问作者Radhika

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:41:42