# Upload a File

This method can handle two different calls, one where a file path is passed, and a second where it does not receive a , and it means we are going to use the MD5 of the file as the file name.

## Using file name:

URL: > files/{bucketname}/{path:.\*}

HTTP Method: PUT

Response: if the file was uploaded, returns:

````javascript
{
  "bucket": "<bucket name>",
  "objectName": "<file name>",
  "parentPath": "<file path>",
  "checksum": "<MD5 checksum>",
  "size": <file size>
}
``

Example

```text
curl -X PUT -T ~/Downloads/image1.jpg PUT http:localhost:8080/files/bucket1/folder1/folder2/image.jpg
``

Response:

```json
{
  "bucket": "bucket1",
  "objectName": "image.jpg",
  "parentPath": "/folder1/folder2/",
  "checksum": "86af350cbceb14672fdcaee11bc2571a",
  "size": 66779
}
````

## Without file name:

URL: > files/{bucketname}/{path:.\*}

HTTP Method: PUT

Response: if the file was uploaded, returns:

```javascript
{
  "bucket": "<bucket name>",
  "objectName": "<MD5 checksum>",
  "parentPath": "/",
  "checksum": "<MD5 checksum>",
  "size": <file size>
}
```

Example:

```
curl -X PUT -T ~/Downloads/image1.jpg PUT http:localhost:8080/files/bucket1
```

Response:

```javascript
{
  "bucket": "bucket1",
  "objectName": "86af350cbceb14672fdcaee11bc2571a",
  "parentPath": "/",
  "checksum": "86af350cbceb14672fdcaee11bc2571a",
  "size": 66779
}
```

## Get a File

```
http://localhost:8080/files/<bucketName>/folder1/folder2/test.deb
```

## Delete a file

```
DELETE 
    http://localhost:8080/files/<bucketName>/{path:.*}
HEADER:
    Bucket: <bucketName>
```

Example:

```
curl --location --request DELETE 'http://localhost:8080/files/my-bucket/folder1/folder2/test.deb' \
--header 'Bucket: <bucketName>'
```

## List Files

This method list all the file names under a bucket and parent path (folder)

Example 1:

```
curl -X GET http:localhost:8080/files/my-bucket/my-folder
```

Example 2:

```
curl -X GET http:localhost:8080/files/my-bucket
```

Response:

```javascript
{
    "files": [
        "diesel.jpg", "LOTR.pdf"
    ]
}
```

## App Ready

Check if the app is ready:

```
curl -v -X GET "http://localhost:8080/appReady"
```


---

# 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://motivlabs.gitbook.io/diesel/api-example-requests/upload-a-file.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.
