作業順利完成,且您已從完成的作業回應中擷取資源名稱後,即可使用 media.download 方法下載包含已產生 SDF 的 ZIP 檔案。
以下範例說明如何使用用戶端程式庫下載產生的檔案:
Java
// Extract download file resource name to use in download requestStringdownloadResourceName=operationResponse.getResponse().get("resourceName").toString();// Configure the Media.download requestMedia.DownloaddownloadRequest=service.media().download(downloadResourceName);// Create output stream for downloaded fileFileOutputStreamoutStream=newFileOutputStream(output-file);// Download filedownloadRequest.executeMediaAndDownloadTo(outStream);System.out.printf("File downloaded to %s\n",outputFile);
Python
# Extract download file resource name to use in download requestresourceName=operation["response"]["resourceName"]# Configure the Media.download requestdownloadRequest=service.media().download_media(resourceName=resourceName)# Create output stream for downloaded fileoutStream=io.FileIO(output-file,mode='wb')# Make downloader objectdownloader=googleHttp.MediaIoBaseDownload(outStream,downloadRequest)# Download media file in chunks until finisheddownload_finished=Falsewhiledownload_finishedisFalse:_,download_finished=downloader.next_chunk()print("File downloaded to %s"%output-file)
PHP
// Get client and set defer so it doesn't immediately return.$client = $this->service->getClient();$client->setDefer(true);// Build media download request.$request = $this->service->media->download( $operation->getResponse()['resourceName'], array('alt' => 'media'));// Call the API, getting the generated SDF.$response = $client->execute($request);$responseBody = $response->getBody();// Writes the downloaded file. If the file already exists, it is// overwritten.file_put_contents(output-file, $responseBody);$client->setDefer(false);printf('File saved to: %s\n', output-file);
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-25 (世界標準時間)。"],[[["\u003cp\u003eAfter a successful operation, download the generated SDFs as a zip file using the \u003ccode\u003emedia.download\u003c/code\u003e method, ensuring the \u003ccode\u003ealt\u003c/code\u003e parameter is set to \u003ccode\u003emedia\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eClient libraries simplify the download process, but if using a direct download URL, append \u003ccode\u003e?alt=media\u003c/code\u003e to ensure proper data format.\u003c/p\u003e\n"],["\u003cp\u003eExtract the download file resource name from the operation response to initiate the download using your preferred client library (Java, Python, or PHP examples provided).\u003c/p\u003e\n"],["\u003cp\u003eDownloaded zip files contain generically named SDF files; a "Skipped" file might be included if certain resources could not be processed, detailing the reasons for exclusion.\u003c/p\u003e\n"],["\u003cp\u003eMinimize skipped resources by utilizing the latest SDF version to ensure compatibility and support for your resource types and states.\u003c/p\u003e\n"]]],["After a successful operation, extract the `resourceName` to download a zip file containing generated SDFs. Use the `media.download` method with `alt=media` to specify the data format. Client libraries automate this process. Download the file by configuring a `Media.Download` request, creating an output stream, and executing the request to download the file into the stream. The zip file contains structured data files like `SDF-LineItems.csv`. A `Skipped.csv` file might be included, listing resources not included and why.\n"],null,["Once your operation has finished successfully and you've extracted the resource\nname from the completed operation response, you are ready to download the zip\nfile containing your generated SDFs using the [`media.download`](/display-video/api/reference/rest/current/media/download)\nmethod.\n| **Note:** You must specify the data format for your download response as `media` through the `alt` parameter. This can be done by appending `?alt=media` to your download url. Client libraries take care of this for you.\n\nHere's an example of how to use a client library to download the resulting file: \n\nJava \n\n```java\n// Extract download file resource name to use in download request\nString downloadResourceName = operationResponse.getResponse()\n .get(\"resourceName\").toString();\n\n// Configure the Media.download request\nMedia.Download downloadRequest =\n service\n .media()\n .download(downloadResourceName);\n\n// Create output stream for downloaded file\nFileOutputStream outStream =\n new FileOutputStream(output-file);\n\n// Download file\ndownloadRequest.executeMediaAndDownloadTo(outStream);\n\nSystem.out.printf(\"File downloaded to %s\\n\", outputFile);\n```\n\nPython \n\n```python\n# Extract download file resource name to use in download request\nresourceName = operation[\"response\"][\"resourceName\"]\n\n# Configure the Media.download request\ndownloadRequest = service.media().download_media(resourceName=resourceName)\n\n# Create output stream for downloaded file\noutStream = io.FileIO(output-file, mode='wb')\n\n# Make downloader object\ndownloader = googleHttp.MediaIoBaseDownload(outStream, downloadRequest)\n\n# Download media file in chunks until finished\ndownload_finished = False\nwhile download_finished is False:\n _, download_finished = downloader.next_chunk()\n\nprint(\"File downloaded to %s\" % output-file)\n```\n\nPHP \n\n```php\n// Get client and set defer so it doesn't immediately return.\n$client = $this-\u003eservice-\u003egetClient();\n$client-\u003esetDefer(true);\n\n// Build media download request.\n$request = $this-\u003eservice-\u003emedia-\u003edownload(\n $operation-\u003egetResponse()['resourceName'],\n array('alt' =\u003e 'media')\n);\n\n// Call the API, getting the generated SDF.\n$response = $client-\u003eexecute($request);\n$responseBody = $response-\u003egetBody();\n\n// Writes the downloaded file. If the file already exists, it is\n// overwritten.\nfile_put_contents(\u003cvar translate=\"no\"\u003eoutput-file\u003c/var\u003e, $responseBody);\n$client-\u003esetDefer(false);\n\nprintf('File saved to: %s\\n', \u003cvar translate=\"no\"\u003eoutput-file\u003c/var\u003e);\n```\n\nOnce your file is downloaded and unzipped, your generated structured data files\nwill be available to you. The generated files will have generic names\nidentifying the SDF file type (example: `SDF-LineItems.csv`).\n\nSkipped files\n\nIf data for a requested resource cannot be included in the corresponding\nstructured data file, the zip file downloaded might include a \"Skipped\" file\n(example: `SDF-LineItems-Skipped.csv`). This file will have a two-column\nstructure, the first containing the IDs of the resources that couldn't be\nincluded and the second containing the reason for their exclusion.\n\nResources may be skipped for many reasons, including being in an unsupported\nstate or of an unsupported type. Avoid having resources skipped by using the\nmost recent version of SDF."]]