> 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/aws-s3-bucket.md).

# AWS S3 Bucket

{% hint style="info" %}
**अधिकांश S3 projects के लिए, उपयोग करें** [**Datasources (Bucket Mirror)**](/roboflow/roboflow-hi/datasets/adding-data/datasources.md)**.** यह आपके bucket से images और metadata को Roboflow में स्वतः और लगातार sync करता है — किसी scripting या manual uploads की आवश्यकता नहीं होती।
{% endhint %}

यह पेज एक बार या ad hoc uploads के लिए दो विकल्पों को कवर करता है:

* **Signed URLs**: presigned URLs का उपयोग करके S3 से सीधे Roboflow में images upload करें, उन्हें पहले locally download किए बिना।
* **CLI Locally**: S3 से images को अपनी local machine पर download करें, फिर उन्हें Roboflow पर upload करें। जब आपको upload करने से पहले images को preprocess या inspect करने की आवश्यकता हो, तब इसका उपयोग करें।

### AWS CLI Setup

Script का उपयोग करने से पहले, सुनिश्चित करें कि आपने आवश्यक authentication credentials के साथ AWS CLI सेट अप कर लिया है। इससे आप वांछित S3 bucket तक पहुँच और उसे manage कर सकेंगे।

* [AWS CLI version 2 इंस्टॉल करना](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html)

#### AWS CLI को configure करना

1. AWS CLI इंस्टॉल करने के बाद, एक terminal या command prompt खोलें।
2. निम्न command चलाएँ:

   ```bash
   aws configure
   ```
3. आपसे अपने AWS credentials दर्ज करने के लिए कहा जाएगा:

   ```
   AWS Access Key ID [None]: YOUR_ACCESS_KEY
   AWS Secret Access Key [None]: YOUR_SECRET_ACCESS_KEY
   Default region name [None]: YOUR_PREFERRED_REGION (उदा., us-west-1)
   Default output format [None]: json
   ```

### विकल्प 1: Signed URL के माध्यम से upload करें:

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

```python
def generate_presigned_url(bucket_name: str, object_name: str, region: str = 'us-east-2') -> str:
    """एक S3 object के लिए presigned URL generate करें।"""
    s3 = boto3.client('s3', region_name=region, config=Config(signature_version='s3v4'))
    url = s3.generate_presigned_url('get_object',
                                    Params={'Bucket': bucket_name, 'Key': object_name},
                                    ExpiresIn=3600)
    return url
```

ऊपर दिए गए code snippet में, आपको अपने S3 bucket का नाम, S3 bucket में image का object name, और aws region चाहिए। Image का signed URL generate होकर return किया जाता है।

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

```python
import boto3
import requests
import urllib.parse
from botocore.config import Config

# ************* इन variables को सेट करें *************
S3_BUCKET_NAME = "YOUR_S3_BUCKET_NAME"
ROBOFLOW_API_KEY = "YOUR_ROBOFLOW_API_KEY"
ROBOFLOW_PROJECT_NAME = "YOUR_ROBOFLOW_PROJECT_NAME"
# ***********************************************

def generate_presigned_url(bucket_name: str, object_name: str, region: str = 'us-east-2') -> str:
    """एक S3 object के लिए presigned URL generate करें।"""
    s3 = boto3.client('s3', region_name=region, config=Config(signature_version='s3v4'))
    url = s3.generate_presigned_url('get_object',
                                    Params={'Bucket': bucket_name, 'Key': object_name},
                                    ExpiresIn=3600)
    return url

def get_s3_objects(bucket_name: str) -> list:
    """दिए गए S3 bucket में object keys की सूची प्राप्त करें।"""
    s3 = boto3.client('s3')
    objects = []
    response = s3.list_objects_v2(Bucket=bucket_name)
    for obj in response['Contents']:
        objects.append(obj['Key'])
    return objects

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__":
    # उपलब्ध images की सूची प्राप्त करें
    available_images = get_s3_objects(S3_BUCKET_NAME)
    
    # वैकल्पिक: यहाँ images को filter करें
    # उदाहरण के लिए, available_images = [img for img in available_images if "some_condition"]
    
    # Roboflow में images upload करें
    for image in available_images:
        presigned_url = generate_presigned_url(S3_BUCKET_NAME, image)
        upload_to_roboflow(ROBOFLOW_API_KEY, ROBOFLOW_PROJECT_NAME, presigned_url)

```

### विकल्प 2: AWS से data को locally download करें

AWS से data upload करने के लिए, पहले `awscli` [command line tool](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)इंस्टॉल करें। यह tool आपको command line पर अपने AWS account के साथ interact करने देता है। Command line tool इंस्टॉल करने के बाद, निम्न command चलाएँ:

```bash
aws s3 sync s3://mybucket/folder_path .
```

बदलें `mybucket` को अपने bucket के नाम से और `folder_path` को उस folder या file के नाम से जिसे आप export करना चाहते हैं। यह command AWS से एक asset को आपकी वर्तमान 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).

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

* [Datasources (Bucket Mirror)](/roboflow/roboflow-hi/datasets/adding-data/datasources.md) — बिना scripting के S3 से continuous, automatic sync
* [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/aws-s3-bucket.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.
