Fumadocs

Upload an image to a planet

Got a crazy good photo of a planet? Share it with the world!

POST
/planets/{planetId}/image
AuthorizationBearer <token>

JWT Bearer token authentication

In: header

Path Parameters

planetIdinteger

The ID of the planet to get

Formatint64

Image to upload

image?file

The image file to upload

Formatbinary

Response Body

curl -X POST "https://galaxy.scalar.com/planets/1/image"
const body = new FormData();

fetch("https://galaxy.scalar.com/planets/1/image", {
  body
})
package main

import (
  "fmt"
  "net/http"
  "io/ioutil"
  "mime/multipart"
  "bytes"
)

func main() {
  url := "https://galaxy.scalar.com/planets/1/image"
  body := new(bytes.Buffer)
  mp := multipart.NewWriter(payload)
  req, _ := http.NewRequest("POST", url, body)
  req.Header.Add("Content-Type", "multipart/form-data")
  res, _ := http.DefaultClient.Do(req)
  defer res.Body.Close()
  body, _ := ioutil.ReadAll(res.Body)

  fmt.Println(res)
  fmt.Println(string(body))
}
import requests

url = "https://galaxy.scalar.com/planets/1/image"
body = {}
response = requests.request("POST", url, data = body, headers = {
  "Content-Type": "multipart/form-data"
})

print(response.text)
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers;
import java.time.Duration;
import java.net.http.HttpRequest.BodyPublishers;

var body = BodyPublishers.ofByteArray(new byte[] { ... });
HttpClient client = HttpClient.newBuilder()
  .connectTimeout(Duration.ofSeconds(10))
  .build();

HttpRequest.Builder requestBuilder = HttpRequest.newBuilder()
  .uri(URI.create("https://galaxy.scalar.com/planets/1/image"))
  .header("Content-Type", "multipart/form-data")
  .POST(body)
  .build();

try {
  HttpResponse<String> response = client.send(requestBuilder.build(), BodyHandlers.ofString());
  System.out.println("Status code: " + response.statusCode());
  System.out.println("Response body: " + response.body());
} catch (Exception e) {
  e.printStackTrace();
}
using System;
using System.Net.Http;
using System.Text;

var body = new MultipartFormDataContent();

var client = new HttpClient();
var response = await client.PostAsync("https://galaxy.scalar.com/planets/1/image", body);
var responseBody = await response.Content.ReadAsStringAsync();
{
  "message": "Image uploaded successfully",
  "imageUrl": "https://cdn.scalar.com/images/8f47c132-9d1f-4f83-b5a4-91db5ee757ab.jpg",
  "uploadedAt": "2024-01-15T14:30:00Z",
  "fileSize": 1048576,
  "mimeType": "image/jpeg"
}
{
  "type": "https://example.com/errors/bad-request",
  "title": "Bad Request",
  "status": 400,
  "detail": "The request was invalid."
}
{
  "type": "https://example.com/errors/forbidden",
  "title": "Forbidden",
  "status": 403,
  "detail": "You are not authorized to access this resource."
}
{
  "type": "https://example.com/errors/not-found",
  "title": "Not Found",
  "status": 404,
  "detail": "The resource you are trying to access does not exist."
}

How is this guide?