How to Insert a File

To insert a file into a collection, make a POST request to the /v1/resource/insert/ endpoint with the required parameters in the body and make sure you use the file type.

To use the file type, the resource can either be provided as URLs or if you are using our SDKs the resource can be the path to the file. Note: File paths only work with our SDKs if you are calling our API’s directly, all files must be provided as URLs. You can consider services like Amazon S3, Cloudinary, or similar platforms to host your files and provide their URLs to the API.

Request Example (File Path)

from wetro import Wetrocloud
    
# Initialize the Wetrocloud client
client = Wetrocloud(api_key="your_api_key")
    
# Insert a file into a Collection
insert_response = client.collection.insert_resource(
    collection_id="my_unique_collection_id",
    resource="./essay/paul_graham_essay.pdf", # Replace with your actual file path
    type="file"
)
    
print(insert_response)

Request Example (File as URL)

from wetro import Wetrocloud
    
# Initialize the Wetrocloud client
client = Wetrocloud(api_key="your_api_key")
    
# Insert a file into a Collection
insert_response = client.collection.insert_resource(
    collection_id="my_unique_collection_id",
    resource="https://didiai-test.s3.us-east-2.amazonaws.com/paul_graham_essay.pdf",
    type="file"
)
    
print(insert_response)

Successful Response

A successful response confirms the operation and tracks token usage.

Example Response

{
  "resource_id": "79621681-b680-4918-948d-d7f8c482426a",
  "success": true,
  "tokens": 35
}
FieldDescription
successIndicates whether the resource was inserted successfully.
tokensNumber of tokens consumed during the operation.
resource_idUnique ID for the resource, this is required when removing a resource