Skip to main content

head

The head method is used to get statistics for a given key.

async function head(
key: string
): Promise<StorageItem>;

Reference

Overview

You can get statistics for a given key, such as contentType, by calling the head method

import { myStorage } from "#elements";

...

const storageItem: StorageItem = await myStorage.head("my-data/string.txt");
console.log(storageItem.contentType);

...

Parameters

  • key: A string that uniquely identifies the object. This string should start and end with letters or numbers, and the middle can contain letters, numbers, dots, slashes, hyphens, or underscores.

Returns

The head method returns a StorageItem object

export type StorageItem = {
key: string; // The unique identifier string for the object
size: number; // The size of the object in bytes
lastModified: string; // The last modified time of the object, in ISO 8601 format
contentType: string; // The mime type of the object
};

Caveats

  • The value of the contentType field is determined by the method you choose to pass when uploads the object using the put method. When you pass data through different methods, you get different contentType values. For more information on how to set contentType, you can refer to the Caveats section of the storage.put method.