Reads a binary body and returns its size, hashes and detected type
POST
https://api.testingapis.com/api/bodies/binaryAccepts application/octet-stream, application/pdf, application/zip, image/png, image/jpeg and image/gif, up to 10MB.
Request body
Optional. application/octet-stream. Raw bytes; returns size, hashes and detected type.
Example body
<raw bytes>Responses
- 200
- Size, SHA-256, MD5, first 16 bytes and the type detected from magic bytes.
- 413
- Body larger than 10MB.
- 415
- Any other Content-Type.
Example
Request
curl -X POST "https://api.testingapis.com/api/bodies/binary" \
-H "Content-Type: application/octet-stream" \
--data-binary @file.binResponse200 OK
{
"contentType": "application/octet-stream",
"size": 8,
"sha256": "4c4b6a3be1314ab86138bef4314dde022e600960d8689a2c8f8631802d20dab6",
"md5": "e9dd2797018cad79186e03e8c5aec8dc",
"first16BytesHex": "89504E470D0A1A0A",
"detectedType": "image/png"
}Code examples
JavaScript (fetch)
const response = await fetch("https://api.testingapis.com/api/bodies/binary", {
method: "POST",
headers: {
"Content-Type": "application/octet-stream",
},
body: "@file.bin",
});
console.log(response.status, await response.text());Python (requests)
import requests
response = requests.request(
"POST",
"https://api.testingapis.com/api/bodies/binary",
headers={
"Content-Type": "application/octet-stream",
},
data="@file.bin".encode("utf-8"),
allow_redirects=False,
)
print(response.status_code, response.text)Java (HttpClient)
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 {
HttpClient client = HttpClient.newBuilder()
.followRedirects(HttpClient.Redirect.NEVER)
.build();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.testingapis.com/api/bodies/binary"))
.header("Content-Type", "application/octet-stream")
.method("POST", HttpRequest.BodyPublishers.ofString("@file.bin"))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode() + " " + response.body());
}
}