जनरेट की गई स्ट्रक्चर्ड डेटा फ़ाइलें (एसडीएफ़), ZIP फ़ाइल में सेव होती हैं. media.download का इस्तेमाल करके, response.resourceName फ़ील्ड में दी गई वैल्यू का इस्तेमाल करके, इस फ़ाइल को डाउनलोड करें.Operation
यहां एसडीएफ़ ZIP फ़ाइल डाउनलोड करने का तरीका बताया गया है:
Java
// Provide the name of the finished sdfdownloadtask operation. String operationName = operation-name; // Provide the path for the output file. String outputFile = output-file; // Retrieve the resource location from the finished operation. Operation operation = service.sdfdownloadtasks().operations().get(operationName).execute(); String fileLocation = operation.getResponse().get("resourceName").toString(); // Configure the Media.download request. Media.Download downloadRequest = service.media().download(fileLocation); // Create output stream for downloaded file. FileOutputStream outStream = new FileOutputStream(outputFile); // Download file. downloadRequest.executeMediaAndDownloadTo(outStream); System.out.printf("File downloaded at %s", outputFile);
Python
# Import the object used for media download. from googleapiclient import http as googleHttp # Provide the name of the successfully completed sdfdownloadtask operation. operation_name = operation-name # Provide the path for the output file. output_path = output-path # Retrieve the completed operation. operation = ( service.sdfdownloadtasks().operations().get(name=operation_name).execute() ) # Retrieve the file location from the operation. file_location = operation["response"]["resourceName"] # Configure the media.download request. download_request = service.media().download_media(resourceName=file_location) # Create output stream for downloaded file. out_stream = io.FileIO(output_path, mode="wb") # Build downloader object. downloader = googleHttp.MediaIoBaseDownload(out_stream, download_request) # Download file in chunks until finished. download_finished = False while download_finished is False: _, download_finished = downloader.next_chunk() print(f"File downloaded at {output_path}.")
PHP
// Provide the name of the finished sdfdownloadtask operation. $operationName = operation-name; // Provide the path for the output file. $outputFile = output-file; try { // Call the API, retrieving the SDF Download Task. $operation = $this->service->sdfdownloadtasks_operations->get( $operationName ); $fileLocation = $operation->getResponse()['resourceName']; $client = $this->service->getClient(); $client->setDefer(true); $request = $this->service->media->download( $fileLocation, 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($outputFile, $responseBody); $client->setDefer(false); } catch (\Exception $e) { $this->renderError($e); return; } printf('<p>File downloaded at %s</p>', $outputFile);
फ़ाइलें एक्सट्रैक्ट करना
जनरेट की गई एसडीएफ़ फ़ाइलों को ZIP फ़ाइल से निकालें. एसडीएफ़, फ़ाइल के टाइप की पहचान करने के लिए सामान्य फ़ाइल नामों का इस्तेमाल करते हैं. लाइन आइटम के एसडीएफ़ का नाम SDF-LineItems.csv है.
ZIP फ़ाइल में, हर फ़ाइल टाइप के लिए "छोड़ी गई" फ़ाइलें शामिल हो सकती हैं. "छोड़ी गई" फ़ाइलें
उन संसाधनों की पहचान करती हैं जिन्हें एसडीएफ़ में शामिल नहीं किया गया है. इनके नाम में -Skipped सफ़िक्स जोड़ा जाता है. इन फ़ाइलों में दो कॉलम होते हैं. पहले कॉलम में, छोड़े गए संसाधन की पहचान की जाती है. दूसरे कॉलम में, उन्हें शामिल न करने की वजह बताई गई है.