Upload File

Upload a file to a bucket. The file path is specified after /files/.

Authentication

Requires X-Glue-Authentication.

Path Parameters

Parameter Type Description
bucket_id string The bucket ID
* string File path

Request Headers

Header Required Description
Content-Type no Initial MIME type. The stored value may be detected from content.

Request

curl -X PUT "https://api.hola.cloud/v1/buckets/bucket-550e8400-e29b-41d4-a716-446655440000/files/images/logo.png" \
  -H 'X-Glue-Authentication: {"user":{"id":"user-123"}}' \
  -H "Content-Type: image/png" \
  --data-binary @logo.png
PUT /v1/buckets/bucket-550e8400-e29b-41d4-a716-446655440000/files/images/logo.png HTTP/1.1
Host: api.hola.cloud
X-Glue-Authentication: {"user":{"id":"user-123"}}
Content-Type: image/png

@logo.png
package main

import (
	"fmt"
	"io"
	"net/http"
	"strings"
)

func main() {
	body := "@logo.png"

	req, err := http.NewRequest("PUT", "https://api.hola.cloud/v1/buckets/bucket-550e8400-e29b-41d4-a716-446655440000/files/images/logo.png", strings.NewReader(body))
	if err != nil {
		panic(err)
	}
	req.Header.Set("X-Glue-Authentication", "{\"user\":{\"id\":\"user-123\"}}")
	req.Header.Set("Content-Type", "image/png")

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	responseBody, err := io.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(responseBody))
}
<?php
$body = '@logo.png';

$ch = curl_init();

curl_setopt_array($ch, [
    CURLOPT_URL => 'https://api.hola.cloud/v1/buckets/bucket-550e8400-e29b-41d4-a716-446655440000/files/images/logo.png',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'PUT',
    CURLOPT_POSTFIELDS => $body,
    CURLOPT_HTTPHEADER => [
        'X-Glue-Authentication: {"user":{"id":"user-123"}}',
        'Content-Type: image/png',
    ],
]);

$response = curl_exec($ch);
if ($response === false) {
    throw new Exception(curl_error($ch));
}
curl_close($ch);

echo $response;
import requests

headers = {
    "X-Glue-Authentication": "{\"user\":{\"id\":\"user-123\"}}",
    "Content-Type": "image/png",
}

body = "@logo.png"

response = requests.request(
    "PUT",
    "https://api.hola.cloud/v1/buckets/bucket-550e8400-e29b-41d4-a716-446655440000/files/images/logo.png",
    headers=headers,
    data=body
)

print(response.text)
const body = "@logo.png";

const response = await fetch("https://api.hola.cloud/v1/buckets/bucket-550e8400-e29b-41d4-a716-446655440000/files/images/logo.png", {
  method: "PUT",
  headers: {
    "X-Glue-Authentication": "{\"user\":{\"id\":\"user-123\"}}",
    "Content-Type": "image/png"
  },
  body
});

console.log(await response.text());
const body = "@logo.png";

const response = await fetch("https://api.hola.cloud/v1/buckets/bucket-550e8400-e29b-41d4-a716-446655440000/files/images/logo.png", {
  method: "PUT",
  headers: {
    "X-Glue-Authentication": "{\"user\":{\"id\":\"user-123\"}}",
    "Content-Type": "image/png"
  },
  body
});

const text = await response.text();
console.log(text);
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
    public static void main(String[] args) throws Exception {
        var body = """
@logo.png
""";

        var request = HttpRequest.newBuilder()
            .uri(URI.create("https://api.hola.cloud/v1/buckets/bucket-550e8400-e29b-41d4-a716-446655440000/files/images/logo.png"))
            .method("PUT", HttpRequest.BodyPublishers.ofString(body))
            .header("X-Glue-Authentication", "{\"user\":{\"id\":\"user-123\"}}")
            .header("Content-Type", "image/png")
            .build();

        var response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}

Response

 1{
 2  "id": "file-9f0b7b3c-1d2e-4a5f-8b9c-0123456789ab",
 3  "uuid": "9f0b7b3c-1d2e-4a5f-8b9c-0123456789ab",
 4  "created_timestamp": 1782045660000000000,
 5  "updated_timestamp": 1782045660000000000,
 6  "owners": ["user-123"],
 7  "status": "available",
 8  "size": 24576,
 9  "name": "images/logo.png",
10  "bucket": "bucket-550e8400-e29b-41d4-a716-446655440000",
11  "hash_md5": "example-md5",
12  "hash_sha256": "example-sha256",
13  "mime_type": "image/png"
14}

Error Codes

Status Description
401 Missing or invalid X-Glue-Authentication
500 Persistence or filesystem error

Comments

Leave a comment