Create a public link
The secrecyClient.cloud.createPublicDataLink method creates a public link targeting a piece of data already uploaded to the cloud. It takes the dataId of that data, a name — the label shown to the recipient — and an expireAt date, which is required but nullable: pass null for a link that never expires. An optional slug lets you choose the public part of the URL instead of letting the server generate it.
const createPublicLink = async ({
dataId,
name,
expireAt,
slug,
}: {
dataId: string;
name: string;
expireAt: Date | null;
slug?: string;
}) => {
// First we need to check if the secrecyClient is available
if (!secrecyClient) {
return null;
}
try {
const link = await secrecyClient.cloud.createPublicDataLink({
dataId,
name,
// null for a link that never expires
expireAt,
// optional, the server generates one when omitted
slug,
});
return link;
} catch (error) {
console.error(error);
return null;
}
};The method resolves with the created link: { id, name, slug, expireAt, dataId, createdByUserId, createdByOrgId, createdByAppId }. The id is what the other methods take to read, update or revoke the link; the slug is what the recipient needs.
Expiration
An expireAt date in the past is rejected before any request is sent: the method throws Unable to create public link using a past expireAt date!. The date can be changed afterwards with secrecyClient.cloud.updatePublicDataLink, so expiring a link is the reversible alternative to revoking it.
The data itself must exist before the link is created — see getting started with transfers for the upload step that produces the dataId.