> For the complete documentation index, see [llms.txt](https://docs.roboflow.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.roboflow.com/roboflow/roboflow-hi/datasets/adding-data/upload-data-from-aws-gcp-and-azure/google-cloud-storage.md).

# Google Cloud Storage

Google Cloud Storage में image data storage को संभालते समय और Roboflow पर upload करते समय, आपके पास आम तौर पर दो विकल्प होते हैं: signed URLs का उपयोग करना या images को स्थानीय रूप से (gsutil CLI के माध्यम से) मैन्युअल रूप से डाउनलोड करके उन्हें स्थानीय रूप से upload करना। इन तरीकों के बीच चुनाव आपके data processing और management की विशिष्ट आवश्यकताओं पर निर्भर करता है।

* **Signed URLs**: यह तरीका विशेष रूप से तब लाभदायक है जब आप images को अपनी local machine पर download करने से जुड़ी अतिरिक्त step और समय-खपत से बचना चाहते हैं। एक signed URL के साथ, आप image data को Google Cloud Storage से सीधे Roboflow API पर upload कर सकते हैं, बिना उसे कभी locally store किए। इससे processing तेज़ होती है और आपकी local system पर कम load पड़ता है।
* **CLI के माध्यम से स्थानीय रूप से**: ऐसे scenarios हो सकते हैं जहाँ आप images को पहले अपने local environment में download करना पसंद करें। उदाहरण के लिए, यदि आपको Roboflow पर upload करने से पहले images को preprocess करना है या manually check करना है, तो local copies होना लाभदायक होगा।

सही method चुनना आपकी specific use-case requirements पर निर्भर करेगा, जैसे data transfer की speed, preprocessing की आवश्यकता, या images की manual inspection।

### Google Cloud JSON Key

Bucket के लिए उपयुक्त permissions के साथ एक service account बनाएं और JSON key file डाउनलोड करें। इस file में वे credentials होंगे जिनका उपयोग आपकी application को authenticate करने के लिए किया जाएगा।

### Option 1: Upload Via Signed URL:

आप Python में Google Cloud SDK का उपयोग करके Google Cloud Storage bucket में अपनी images के लिए signed URLs generate कर सकते हैं।

```python
def get_gcs_signed_url(bucket_name: str, blob_name: str) -> str:
    """GCS object के लिए एक signed URL generate करें."""
    storage_client = storage.Client.from_service_account_json(GOOGLE_APPLICATION_CREDENTIALS)
    bucket = storage_client.get_bucket(bucket_name)
    blob = bucket.get_blob(blob_name)
    
    url = blob.generate_signed_url(
        version="v4",
        expiration=3600,  # 1 hour in seconds
        method="GET"
    )
    return url
```

ऊपर दिए गए code snippet में, आपको अपने Google Cloud Storage bucket का नाम और blob name चाहिए। image का signed URL generate होकर वापस किया जाता है।

इसके आधार पर, हम एक complete solution बना सकते हैं जो bucket में उपलब्ध सभी objects को pull करता है, और फिर उन्हें API के माध्यम से Roboflow पर upload करता है। इस solution का outline नीचे देखा जा सकता है:

```python
from google.cloud import storage
import requests
import urllib.parse

# ************* इन variables को सेट करें *************
GCS_BUCKET_NAME = "YOUR_GCS_BUCKET_NAME"
ROBOFLOW_API_KEY = "YOUR_ROBOFLOW_API_KEY"
ROBOFLOW_PROJECT_NAME = "YOUR_ROBOFLOW_PROJECT_NAME"
GOOGLE_APPLICATION_CREDENTIALS = "path/to/your-service-account-file.json"
# ***********************************************

def get_gcs_signed_url(bucket_name: str, blob_name: str) -> str:
    """GCS object के लिए एक signed URL generate करें."""
    storage_client = storage.Client.from_service_account_json(GOOGLE_APPLICATION_CREDENTIALS)
    bucket = storage_client.get_bucket(bucket_name)
    blob = bucket.get_blob(blob_name)
    
    url = blob.generate_signed_url(
        version="v4",
        expiration=3600,  # 1 hour in seconds
        method="GET"
    )
    return url

def get_gcs_objects(bucket_name: str) -> list:
    """दिए गए GCS bucket में object keys की सूची प्राप्त करें."""
    storage_client = storage.Client.from_service_account_json(GOOGLE_APPLICATION_CREDENTIALS)
    bucket = storage_client.get_bucket(bucket_name)
    blobs = bucket.list_blobs()

    object_names = []
    for blob in blobs:
        object_names.append(blob.name)
    return object_names

def upload_to_roboflow(api_key: str, project_name: str, presigned_url: str, img_name='', split="train"):
    """Roboflow पर एक image upload करें."""
    API_URL = "https://api.roboflow.com"
    if img_name == '':
        img_name = presigned_url.split("/")[-1]

    upload_url = "".join([
        API_URL + "/dataset/" + project_name + "/upload",
        "?api_key=" + api_key,
        "&name=" + img_name,
        "&split=" + split,
        "&image=" + urllib.parse.quote_plus(presigned_url),
    ])
    response = requests.post(upload_url)

    # response code जांचें
    if response.status_code == 200:
        print(f"{img_name} को सफलतापूर्वक {project_name} पर upload किया गया")
        return True
    else:
        print(f"{img_name} को upload करने में विफल। Error: {response.content.decode('utf-8')}")
        return False

if __name__ == "__main__":
    # उपलब्ध blobs की सूची प्राप्त करें
    available_blobs = get_gcs_objects(GCS_BUCKET_NAME)
    
    # वैकल्पिक: यहाँ blobs को filter करें
    # जैसे, available_blobs = [blob for blob in available_blobs if "some_condition"]
    
    # blobs को Roboflow पर upload करें
    for blob in available_blobs:
        blob_url = get_gcs_signed_url(GCS_BUCKET_NAME, blob)
        upload_to_roboflow(ROBOFLOW_API_KEY, ROBOFLOW_PROJECT_NAME, blob_url)

```

### Option 2: GCP से Data को स्थानीय रूप से डाउनलोड करें

GCP से data डाउनलोड करने के लिए, पहले GCP CLI install करें। फिर, अपने GCP user account से authenticate करें।

किसी image या images के folder को डाउनलोड करने के लिए, निम्न command का उपयोग करें:

```bash
gsutil cp -r gs://mybucket/folder .
```

बदलें `mybucket` को अपने GCP storage bucket के नाम से और `folder` को उस file या folder के destination से जिसे आप copy करना चाहते हैं। यह command target file या folder को आपकी current working directory (`.`).

### Roboflow पर Data Upload करें

अब जब हमने data डाउनलोड कर लिया है, हम इसे Roboflow पर या तो [Upload Web Interface](/roboflow/roboflow-hi/datasets/adding-data.md#upload-data-with-the-web-application) का उपयोग करके या [Roboflow CLI](/roboflow/roboflow-hi/datasets/adding-data.md#upload-datasets-with-the-command-line).

### यह भी देखें

* [Roboflow project ID प्राप्त करें](https://docs.roboflow.com/api-reference/workspace-and-project-ids)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.roboflow.com/roboflow/roboflow-hi/datasets/adding-data/upload-data-from-aws-gcp-and-azure/google-cloud-storage.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
