Loading MODEL_3D media with productCreate

I have downloaded a glb file from the Porsche 718 GT4 RS - DownloadFree3D.com URL and try to upload the file in the file path source/2022_porsche_718_cayman_gt4_rs.glb using programatically.

Step 1: Generate the upload URL and parameters

Query:

mutation stagedUploadsCreate($input: [StagedUploadInput!]!) {
  stagedUploadsCreate(input: $input) {
    stagedTargets {
      url
      resourceUrl
      parameters {
        name
        value
      }
    }
  }
}

Variables:

{
  "input": [
    {
      "filename": "2022_porsche_718_cayman_gt4_rs.glb",
      "mimeType": "model/gltf-binary",
      "resource": "MODEL_3D",
      "fileSize": "19082036"
    }
  ]
}

  • ls -l 2022_porsche_718_cayman_gt4_rs.glb: Run the command to check the file size and replace with fileSize field.

Step 2: Upload the asset

Replace the parameters with the above query response:

curl -v \
  -F "GoogleAccessId=threed-model-service-prod@threed-model-service.iam.gserviceaccount.com" \
  -F "key=models/186459da1e7eaadd/2022_porsche_718_cayman_gt4_rs.glb" \
  -F "policy=eyJleHBpcmF0aW9uIjoiMjAyNC0xMS0xOFQxNzowMDoxOFoiLCJjb25kaXRpb25zIjpbWyJlcSIsIiRidWNrZXQiLCJ0aHJlZWQtbW9kZWxzLXByb2R1Y3Rpb24iXSxbImVxIiwiJGtleSIsIm1vZGVscy8xODY0NTlkYTFlN2VhYWRkLzIwMjJfcG9yc2NoZV83MThfY2F5bWFuX2d0NF9ycy5nbGIiXSxbImNvbnRlbnQtbGVuZ3RoLXJhbmdlIiwxOTA4MjAzNiwxOTA4MjAzNl1dfQ==" \
  -F "signature=k7wzhLa6vg0A10W6+RqXKORbxdnsrqqKYhM/lD8tGMfQJYdRNhL2s8BNq+BKK9c+BK7sycIfeqfY9ce/jr/Ied+w5tDmtnn+mtfDQP8YKc1d2bQCJXXE1BFgD0j4hy+TL4nQAzfydKxs6OwafR+8MDxQIZfNnyGi/qgmw3VYz6f8vfASdnKqyHlX+wDKE7uSKIytz+Vk99HAoT7bZEJ+q4lBdIi/55TuUjxvB5HPq1tekzHk4SSc1e8Zy1BwgTHK11uxFNNAsMILY+PvRWF2r9vIN26hWvsJlh2K2XakKVGefPr0Fiw/IYx/a236W60anJ3KrwpFbRneD/Y1369cNA==" \
  -F "file=@/2022_porsche_718_cayman_gt4_rs.glb" \
  "https://storage.googleapis.com/threed-models-production/models/186459da1e7eaadd/2022_porsche_718_cayman_gt4_rs.glb?external_model3d_id=bW9kZWwzZC0xMDkwMjA5"
  • file=@/2022_porsche_718_cayman_gt4_rs.glb" : Replace with your filename in your local machine.
  • Open the terminal where the file is located and run the curl command.

Step 3: Add media to a product

Query:

mutation createProduct($productSet: ProductSetInput!, $synchronous: Boolean!) {
  productSet(synchronous: $synchronous, input: $productSet) {
    product {
      id
      media(first: 5) {
        nodes {
          id
          alt
          mediaContentType
          status
        }
      }
    }
    userErrors {
      field
      message
    }
  }
}

Variables:

{
  "synchronous": true,
  "productSet": {
    "title": "Winter hat",
    "files": [
      {
        "originalSource": "https://storage.googleapis.com/threed-models-production/models/186459da1e7eaadd/2022_porsche_718_cayman_gt4_rs.glb?external_model3d_id=bW9kZWwzZC0xMDkwMjA5",
        "alt": "An elegant grey hat",
        "contentType": "MODEL_3D"
      }
    ]
  }
}

Replace the originalSource.

Successfully executed the query, created the product with uploaded file. Its worked.

1 Like