Save a file

Import the function at the top of your file

import { saveFile } from "swizzle-js";

Upload a file to storage with saveFile(fileName, fileData, isPrivate?, allowedUsers?)

  • fileName is the filename (searchable later, does not have to be unique). Include the file extension.

  • fileData is the data you'd like to upload.

  • isPrivate if this is set to true, the URL will not be accessible unless signed by the getFile function or the user is in allowedUsers.

  • allowedUsers is an array of userIds. If these users pass their access token in the Authorization header or under the token parameter in the query string, they will be allowed to access the file automatically.

Returns the hosted file URL (unsigned)

const url = await saveFile(fileName, fileData, isPrivate, allowedUsers)

You can upload multiple files with the same filename. It's much better to store the url returned by the saveFile function, since it's guaranteed to be unique.

Last updated