Files API (Draft WIP) - lolmaxz/vrc-ts GitHub Wiki

Files API Documentation

The Files API allows you to manage files within the VRChat platform. This includes creating files, uploading file versions, downloading files, and performing various file-related operations. Files in VRChat are used for various purposes, such as avatars, worlds, images, and other content.


Index

  1. listFiles - Retrieve a list of files.
  2. createFile - Create a new file object.
  3. showFile - Get information about a specific file.
  4. createFileVersion - Create a new version for a file.
  5. deleteFile - Delete a file object.
  6. downloadFileVersion - Download a specific version of a file.
  7. deleteFileVersion - Delete a specific version of a file.
  8. finishFileDataUpload - Complete the upload of a file data.
  9. startFileDataUpload - Initiate the upload of a file data.
  10. checkFileDataUploadStatus - Check the status of a file data upload.
  11. getFileVersionAnalysis - Get analysis information for a file version.
  12. getFileVersionAnalysisSecurity - Get security analysis for a file version.
  13. getFileVersionAnalysisStandard - Get standard analysis for a file version.

Endpoints

1. listFiles

Retrieve a list of files.

Purpose

Retrieve a list of files available to the user, optionally filtering by tag and controlling pagination.

Method Signature

listFiles(options: {
  tag?: string;
  n?: number;
  offset?: number;
}): Promise<File[]>

Parameters

  • options (object):

    • tag (string, optional):
      Filter files by a specific tag.

    • n (number, optional):
      Number of files to retrieve (1-100). Default is implementation-specific.

    • offset (number, optional):
      Offset from the first file. Must be 0 or greater.

Returns

  • Promise<File[]>: A promise that resolves to an array of file objects.

Example Usage

// Example: List files with a specific tag
const files = await vrchatApi.filesApi.listFiles({
  tag: 'avatar',
  n: 20,
});
console.log(files);

2. createFile

Create a new file object.

Purpose

Create a new file object in VRChat. This does not upload any data; it only creates the file metadata. You can then upload data to this file by creating versions.

Method Signature

createFile(options: {
  name: string;
  mimeType: string;
  extension?: string;
  tags?: string[];
}): Promise<File>

Parameters

  • options (object):

    • name (string, required):
      The name of the file.

    • mimeType (string, required):
      The MIME type of the file (e.g., 'application/zip', 'image/png').

    • extension (string, optional):
      The file extension (e.g., 'zip', 'png').

    • tags (string array, optional):
      An array of tags associated with the file.

Returns

  • Promise<File>: A promise that resolves to the created file object.

Example Usage

// Example: Create a new file
const newFile = await vrchatApi.filesApi.createFile({
  name: 'MyAvatar',
  mimeType: 'application/zip',
  extension: 'zip',
  tags: ['avatar', 'custom'],
});
console.log(newFile);

3. showFile

Get information about a specific file.

Purpose

Retrieve detailed information about a specific file by its file ID. This includes metadata and version information.

Method Signature

showFile(options: {
  fileId: string;
}): Promise<File>

Parameters

  • options (object):

    • fileId (string, required):
      The ID of the file to retrieve.

Returns

  • Promise<File>: A promise that resolves to the file object.

Example Usage

// Example: Get information about a file
const fileInfo = await vrchatApi.filesApi.showFile({
  fileId: 'file_abcdef12-3456-7890-abcd-ef1234567890',
});
console.log(fileInfo);

4. createFileVersion

Create a new version for a file.

Purpose

Create a new version for an existing file. This prepares the file to accept new data uploads for this version.

Method Signature

createFileVersion(options: {
  fileId: string;
  signatureMd5: string;
  signatureSizeInBytes: number;
  fileMd5?: string;
  fileSizeInBytes?: number;
}): Promise<File>

Parameters

  • options (object):

    • fileId (string, required):
      The ID of the file to create a new version for.

    • signatureMd5 (string, required):
      The MD5 hash of the signature file.

    • signatureSizeInBytes (number, required):
      The size of the signature file in bytes.

    • fileMd5 (string, optional):
      The MD5 hash of the main file data.

    • fileSizeInBytes (number, optional):
      The size of the main file data in bytes.

Returns

  • Promise<File>: A promise that resolves to the file object, including the new version.

Example Usage

// Example: Create a new file version
const updatedFile = await vrchatApi.filesApi.createFileVersion({
  fileId: 'file_abcdef12-3456-7890-abcd-ef1234567890',
  signatureMd5: 'd41d8cd98f00b204e9800998ecf8427e',
  signatureSizeInBytes: 12345,
  fileMd5: 'd41d8cd98f00b204e9800998ecf8427e',
  fileSizeInBytes: 67890,
});
console.log(updatedFile);

5. deleteFile

Delete a file object.

Purpose

Delete an existing file object from VRChat. This action is irreversible.

Method Signature

deleteFile(options: {
  fileId: string;
}): Promise<RequestSuccess>

Parameters

  • options (object):

    • fileId (string, required):
      The ID of the file to delete.

Returns

  • Promise<RequestSuccess>: A promise that resolves to a success object indicating the operation was successful.

Example Usage

// Example: Delete a file
const response = await vrchatApi.filesApi.deleteFile({
  fileId: 'file_abcdef12-3456-7890-abcd-ef1234567890',
});
console.log(response); // { success: true }

6. downloadFileVersion

Download a specific version of a file.

Purpose

Download a specific version of a file. Version 0 is always when the file was created; real data is usually located in version 1 and up.

Method Signature

downloadFileVersion(options: {
  fileId: string;
  versionId: number;
}): Promise<FileData>

Parameters

  • options (object):

    • fileId (string, required):
      The ID of the file to download.

    • versionId (number, required):
      The version number of the file to download.

Returns

  • Promise<FileData>: A promise that resolves to the file data.

Example Usage

// Example: Download a specific version of a file
const fileData = await vrchatApi.filesApi.downloadFileVersion({
  fileId: 'file_abcdef12-3456-7890-abcd-ef1234567890',
  versionId: 1,
});
// Handle fileData (e.g., save to disk)

7. deleteFileVersion

Delete a specific version of a file.

Purpose

Delete a specific version of a file. You can only delete the latest version.

Method Signature

deleteFileVersion(options: {
  fileId: string;
  versionId: number;
}): Promise<RequestSuccess>

Parameters

  • options (object):

    • fileId (string, required):
      The ID of the file.

    • versionId (number, required):
      The version number to delete.

Returns

  • Promise<RequestSuccess>: A promise that resolves to a success object indicating the operation was successful.

Example Usage

// Example: Delete the latest version of a file
const response = await vrchatApi.filesApi.deleteFileVersion({
  fileId: 'file_abcdef12-3456-7890-abcd-ef1234567890',
  versionId: 2,
});
console.log(response); // { success: true }

8. finishFileDataUpload

Complete the upload of a file data.

Purpose

Finish the upload process for a file data after all parts have been uploaded. This will mark the upload as complete.

Method Signature

finishFileDataUpload(options: {
  fileId: string;
  versionId: number;
  fileType: 'file' | 'signature';
  etags: string[];
}): Promise<File>

Parameters

  • options (object):

    • fileId (string, required):
      The ID of the file.

    • versionId (number, required):
      The version number.

    • fileType (string, required):
      The type of file data. Options: 'file', 'signature'.

    • etags (string array, required):
      An array of ETags returned from the upload of each part.

Returns

  • Promise<File>: A promise that resolves to the file object.

Example Usage

// Example: Finish file data upload
const updatedFile = await vrchatApi.filesApi.finishFileDataUpload({
  fileId: 'file_abcdef12-3456-7890-abcd-ef1234567890',
  versionId: 1,
  fileType: 'file',
  etags: ['etag1', 'etag2', 'etag3'],
});
console.log(updatedFile);

9. startFileDataUpload

Initiate the upload of a file data.

Purpose

Start the upload process for a specific part of a file data. This endpoint returns a pre-signed AWS S3 URL to which you can upload the data using an HTTP PUT request.

Method Signature

startFileDataUpload(options: {
  fileId: string;
  versionId: number;
  fileType: 'file' | 'signature';
}): Promise<UploadInfo>

Parameters

  • options (object):

    • fileId (string, required):
      The ID of the file.

    • versionId (number, required):
      The version number.

    • fileType (string, required):
      The type of file data. Options: 'file', 'signature'.

Returns

  • Promise<UploadInfo>: A promise that resolves to an object containing upload information, including the AWS S3 URL.

Example Usage

// Example: Start file data upload
const uploadInfo = await vrchatApi.filesApi.startFileDataUpload({
  fileId: 'file_abcdef12-3456-7890-abcd-ef1234567890',
  versionId: 1,
  fileType: 'file',
});
console.log(uploadInfo);
// Use uploadInfo.url to upload the file part using HTTP PUT

10. checkFileDataUploadStatus

Check the status of a file data upload.

Purpose

Retrieve the upload status of a file data. Can be accessed when the status is 'waiting'. Trying to access it on a file version already uploaded may result in a timeout.

Method Signature

checkFileDataUploadStatus(options: {
  fileId: string;
  versionId: number;
  fileType: 'file' | 'signature';
}): Promise<FileVersionStatus>

Parameters

  • options (object):

    • fileId (string, required):
      The ID of the file.

    • versionId (number, required):
      The version number.

    • fileType (string, required):
      The type of file data. Options: 'file', 'signature'.

Returns

  • Promise<FileVersionStatus>: A promise that resolves to an object containing the upload status.

Example Usage

// Example: Check file data upload status
const status = await vrchatApi.filesApi.checkFileDataUploadStatus({
  fileId: 'file_abcdef12-3456-7890-abcd-ef1234567890',
  versionId: 1,
  fileType: 'file',
});
console.log(status);

11. getFileVersionAnalysis

Get analysis information for a file version.

Purpose

Retrieve analysis information for a specific file version. This may include various metrics and data about the file.

Method Signature

getFileVersionAnalysis(options: {
  fileId: string;
  versionId: number;
}): Promise<FileAnalysis>

Parameters

  • options (object):

    • fileId (string, required):
      The ID of the file.

    • versionId (number, required):
      The version number.

Returns

  • Promise<FileAnalysis>: A promise that resolves to the file analysis object.

Example Usage

// Example: Get file version analysis
const analysis = await vrchatApi.filesApi.getFileVersionAnalysis({
  fileId: 'file_abcdef12-3456-7890-abcd-ef1234567890',
  versionId: 1,
});
console.log(analysis);

12. getFileVersionAnalysisSecurity

Get security analysis for a file version.

Purpose

Retrieve security analysis information for a specific file version. This may include information about any potential security issues.

Method Signature

getFileVersionAnalysisSecurity(options: {
  fileId: string;
  versionId: number;
}): Promise<FileAnalysis>

Parameters

  • Same as in getFileVersionAnalysis

Returns

  • Promise<FileAnalysis>: A promise that resolves to the security analysis object.

Example Usage

// Example: Get file version security analysis
const securityAnalysis = await vrchatApi.filesApi.getFileVersionAnalysisSecurity({
  fileId: 'file_abcdef12-3456-7890-abcd-ef1234567890',
  versionId: 1,
});
console.log(securityAnalysis);

13. getFileVersionAnalysisStandard

Get standard analysis for a file version.

Purpose

Retrieve standard analysis information for a specific file version.

Method Signature

getFileVersionAnalysisStandard(options: {
  fileId: string;
  versionId: number;
}): Promise<FileAnalysis>

Parameters

  • Same as in getFileVersionAnalysis

Returns

  • Promise<FileAnalysis>: A promise that resolves to the standard analysis object.

Example Usage

// Example: Get file version standard analysis
const standardAnalysis = await vrchatApi.filesApi.getFileVersionAnalysisStandard({
  fileId: 'file_abcdef12-3456-7890-abcd-ef1234567890',
  versionId: 1,
});
console.log(standardAnalysis);

Additional Types and Enums

File Object Structure

type File = {
  id: string; // File ID
  ownerId: string;
  name: string;
  mimeType: string;
  extension?: string;
  tags: string[];
  versions: FileVersion[];
  createdAt: string;
  updatedAt: string;
};

FileVersion Object Structure

type FileVersion = {
  version: number;
  status: 'waiting' | 'complete' | 'failed';
  fileSizeInBytes?: number;
  fileMd5?: string;
  signatureSizeInBytes: number;
  signatureMd5: string;
  createdAt: string;
  updatedAt: string;
};

RequestSuccess Object Structure

type RequestSuccess = {
  success: boolean;
};

UploadInfo Object Structure

type UploadInfo = {
  url: string; // Pre-signed AWS S3 URL
  partNumber: number;
  uploadId: string;
  headers: { [key: string]: string }; // Additional headers required for the upload
};

FileVersionStatus Object Structure

type FileVersionStatus = {
  status: 'waiting' | 'in_progress' | 'complete' | 'failed';
  message?: string;
};

FileAnalysis Object Structure

type FileAnalysis = {
  // Analysis data specific to the file version
  // Structure may vary depending on the analysis type
};

Additional Notes

  • File Versions: Files can have multiple versions. Each version can have its own data and analysis.

  • Upload Process:

    • To upload a file, you typically create a file, create a file version, start uploading data using startFileDataUpload, upload the data to the provided URL, and then finish the upload with finishFileDataUpload.
  • AWS S3 Uploads:

    • The upload URLs provided are pre-signed AWS S3 URLs. You must upload the file data using an HTTP PUT request to these URLs.
  • ETags:

    • When uploading parts to AWS S3, AWS returns an ETag for each part. These ETags must be collected and provided when finishing the upload.
  • File Types:

    • The fileType parameter typically accepts 'file' or 'signature'. For avatars and worlds, you often need to upload both the main file and a signature file.
  • Error Handling:

    • Ensure to handle errors appropriately, especially during the upload process, as partial uploads can leave files in an inconsistent state.

Endpoints:

  1. listFiles - Retrieve a list of files.
  2. createFile - Create a new file object.
  3. showFile - Get information about a specific file.
  4. createFileVersion - Create a new version for a file.
  5. deleteFile - Delete a file object.
  6. downloadFileVersion - Download a specific version of a file.
  7. deleteFileVersion - Delete a specific version of a file.
  8. finishFileDataUpload - Complete the upload of a file data.
  9. startFileDataUpload - Initiate the upload of a file data.
  10. checkFileDataUploadStatus - Check the status of a file data upload.
  11. getFileVersionAnalysis - Get analysis information for a file version.
  12. getFileVersionAnalysisSecurity - Get security analysis for a file version.
  13. getFileVersionAnalysisStandard - Get standard analysis for a file version.

⚠️ **GitHub.com Fallback** ⚠️