# Azure Blob Storage

Azure Blob Storage में इमेज डेटा स्टोरेज को संभालते समय और Roboflow पर अपलोड करते समय, आपके पास आम तौर पर दो विकल्प होते हैं: signed URLs का उपयोग करना या images को मैन्युअल रूप से लोकली डाउनलोड करना (Azure CLI के माध्यम से) ताकि उन्हें लोकली अपलोड किया जा सके। इन तरीकों के बीच चुनाव आपकी डेटा प्रोसेसिंग और मैनेजमेंट की विशिष्ट जरूरतों पर निर्भर करता है।

* **Signed URLs**: यह तरीका विशेष रूप से फायदेमंद है यदि आप images को अपने local machine पर डाउनलोड करने से जुड़ा अतिरिक्त चरण और समय की खपत से बचना चाहते हैं। signed URL के साथ, आप image data को Azure Blob Storage से सीधे Roboflow API पर बिना इसे कभी locally store किए अपलोड कर सकते हैं। इससे processing तेज़ होती है और आपके local system पर लोड कम पड़ता है।
* **CLI Locally**: ऐसे 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।

### Azure Connection String

Storage Account बनाने के बाद, आप Azure portal में "Security + networking" के तहत "Access keys" सेक्शन में access keys या connection string पा सकते हैं। इन credentials का उपयोग आपके application को authenticate करने के लिए किया जाता है।

### Option 1: Upload Via Signed URL:

आप Azure SDK in Python द्वारा Azure Blob Storage में अपने images के लिए signed URLs generate कर सकते हैं।

```python
def get_blob_sas_url(blob_service_client, container_name: str, blob_name: str) -> str:
    """Azure Blob के लिए एक SAS URL generate करें."""
    from azure.storage.blob import generate_blob_sas, BlobSasPermissions
    from datetime import datetime, timedelta

    sas_token = generate_blob_sas(
        blob_service_client.account_name,
        container_name,
        blob_name,
        account_key=blob_service_client.credential.account_key,
        permission=BlobSasPermissions(read=True),
        expiry=datetime.utcnow() + timedelta(hours=1)
    )
    
    blob_url = f"https://{blob_service_client.account_name}.blob.core.windows.net/{container_name}/{blob_name}?{sas_token}"
    return blob_url
```

ऊपर दिए गए code snippet में, आपको blob service client, container name, और blob name की आवश्यकता होगी। image का signed URL generate होकर return किया जाता है।

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

```python
from azure.storage.blob import BlobServiceClient
import requests
import urllib.parse

# ************* इन variables को सेट करें *************
AZURE_CONNECTION_STRING = "YOUR_AZURE_CONNECTION_STRING"
AZURE_CONTAINER_NAME = "YOUR_AZURE_CONTAINER_NAME"
ROBOFLOW_API_KEY = "YOUR_ROBOFLOW_API_KEY"
ROBOFLOW_PROJECT_NAME = "YOUR_ROBOFLOW_PROJECT_NAME"
# ***********************************************

def get_blob_sas_url(blob_service_client, container_name: str, blob_name: str) -> str:
    """Azure Blob के लिए एक SAS URL generate करें."""
    from azure.storage.blob import generate_blob_sas, BlobSasPermissions
    from datetime import datetime, timedelta

    sas_token = generate_blob_sas(
        blob_service_client.account_name,
        container_name,
        blob_name,
        account_key=blob_service_client.credential.account_key,
        permission=BlobSasPermissions(read=True),
        expiry=datetime.utcnow() + timedelta(hours=1)
    )
    
    blob_url = f"https://{blob_service_client.account_name}.blob.core.windows.net/{container_name}/{blob_name}?{sas_token}"
    return blob_url

def get_azure_blob_objects(container_name: str) -> list:
    """दिए गए Azure Blob container में blob names की list प्राप्त करें."""
    blob_service_client = BlobServiceClient.from_connection_string(AZURE_CONNECTION_STRING)
    container_client = blob_service_client.get_container_client(container_name)
    
    blobs = []
    blob_list = container_client.list_blobs()
    for blob in blob_list:
        blobs.append(blob.name)
    return blobs

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 की सूची fetch करें
    available_blobs = get_azure_blob_objects(AZURE_CONTAINER_NAME)
    
    # वैकल्पिक: यहाँ blobs को filter करें
    # उदाहरण: available_blobs = [blob for blob in available_blobs if "some_condition"]
    
    # Initialize Azure Blob Service Client
    blob_service_client = BlobServiceClient.from_connection_string(AZURE_CONNECTION_STRING)
    
    # blobs को Roboflow पर upload करें
    for blob in available_blobs:
        blob_url = get_blob_sas_url(blob_service_client, AZURE_CONTAINER_NAME, blob)
        upload_to_roboflow(ROBOFLOW_API_KEY, ROBOFLOW_PROJECT_NAME, blob_url)

```

### विकल्प 2: Azure से डेटा को लोकली डाउनलोड करें

सबसे पहले, `azcopy` command line utility इंस्टॉल करें। यह utility आपको Azure Storage से files और folders डाउनलोड करने देती है। फिर, एक [Shared Access Signature](https://learn.microsoft.com/en-us/azure/storage/common/storage-sas-overview) token का उपयोग करके अपने Azure account से authenticate करें। आप इसके बारे में और जान सकते हैं [SAS token कैसे retrieve करें](https://learn.microsoft.com/en-us/azure/storage/common/storage-sas-overview) azcopy documentation में।

एक बार जब आपके पास `azcopy` set up हो जाए, तो file या folder डाउनलोड करने के लिए निम्न command चलाएँ:

```bash
azcopy copy "C:\local\path" <sas-token> --recursive=true
```

इसे बदलें `C:\local\path` को उस folder या file के path से बदलें जिसे आप डाउनलोड करना चाहते हैं। `<sas-token>` value को authentication के लिए SAS token से बदलें। यदि आप files और folders को recursively डाउनलोड करना चाहते हैं, तो ऊपर की तरह `--recursive=true` argument निर्दिष्ट करें। अन्यथा, इस argument को हटा दें।

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

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

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

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


---

# Agent Instructions: 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/azure-blob-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.
