Files API (Draft WIP) - lolmaxz/vrc-ts GitHub Wiki
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.
-
listFiles
- Retrieve a list of files. -
createFile
- Create a new file object. -
showFile
- Get information about a specific file. -
createFileVersion
- Create a new version for a file. -
deleteFile
- Delete a file object. -
downloadFileVersion
- Download a specific version of a file. -
deleteFileVersion
- Delete a specific version of a file. -
finishFileDataUpload
- Complete the upload of a file data. -
startFileDataUpload
- Initiate the upload of a file data. -
checkFileDataUploadStatus
- Check the status of a file data upload. -
getFileVersionAnalysis
- Get analysis information for a file version. -
getFileVersionAnalysisSecurity
- Get security analysis for a file version. -
getFileVersionAnalysisStandard
- Get standard analysis for a file version.
Retrieve a list of files.
Retrieve a list of files available to the user, optionally filtering by tag and controlling pagination.
listFiles(options: {
tag?: string;
n?: number;
offset?: number;
}): Promise<File[]>
-
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.
-
-
Promise<File[]>
: A promise that resolves to an array of file objects.
// Example: List files with a specific tag
const files = await vrchatApi.filesApi.listFiles({
tag: 'avatar',
n: 20,
});
console.log(files);
Create a new file object.
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.
createFile(options: {
name: string;
mimeType: string;
extension?: string;
tags?: string[];
}): Promise<File>
-
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.
-
-
Promise<File>
: A promise that resolves to the created file object.
// Example: Create a new file
const newFile = await vrchatApi.filesApi.createFile({
name: 'MyAvatar',
mimeType: 'application/zip',
extension: 'zip',
tags: ['avatar', 'custom'],
});
console.log(newFile);
Get information about a specific file.
Retrieve detailed information about a specific file by its file ID. This includes metadata and version information.
showFile(options: {
fileId: string;
}): Promise<File>
-
options
(object):-
fileId
(string, required):
The ID of the file to retrieve.
-
-
Promise<File>
: A promise that resolves to the file object.
// Example: Get information about a file
const fileInfo = await vrchatApi.filesApi.showFile({
fileId: 'file_abcdef12-3456-7890-abcd-ef1234567890',
});
console.log(fileInfo);
Create a new version for a file.
Create a new version for an existing file. This prepares the file to accept new data uploads for this version.
createFileVersion(options: {
fileId: string;
signatureMd5: string;
signatureSizeInBytes: number;
fileMd5?: string;
fileSizeInBytes?: number;
}): Promise<File>
-
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.
-
-
Promise<File>
: A promise that resolves to the file object, including the new version.
// 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);
Delete a file object.
Delete an existing file object from VRChat. This action is irreversible.
deleteFile(options: {
fileId: string;
}): Promise<RequestSuccess>
-
options
(object):-
fileId
(string, required):
The ID of the file to delete.
-
-
Promise<RequestSuccess>
: A promise that resolves to a success object indicating the operation was successful.
// Example: Delete a file
const response = await vrchatApi.filesApi.deleteFile({
fileId: 'file_abcdef12-3456-7890-abcd-ef1234567890',
});
console.log(response); // { success: true }
Download a specific version of a file.
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.
downloadFileVersion(options: {
fileId: string;
versionId: number;
}): Promise<FileData>
-
options
(object):-
fileId
(string, required):
The ID of the file to download. -
versionId
(number, required):
The version number of the file to download.
-
-
Promise<FileData>
: A promise that resolves to the file data.
// 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)
Delete a specific version of a file.
Delete a specific version of a file. You can only delete the latest version.
deleteFileVersion(options: {
fileId: string;
versionId: number;
}): Promise<RequestSuccess>
-
options
(object):-
fileId
(string, required):
The ID of the file. -
versionId
(number, required):
The version number to delete.
-
-
Promise<RequestSuccess>
: A promise that resolves to a success object indicating the operation was successful.
// 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 }
Complete the upload of a file data.
Finish the upload process for a file data after all parts have been uploaded. This will mark the upload as complete.
finishFileDataUpload(options: {
fileId: string;
versionId: number;
fileType: 'file' | 'signature';
etags: string[];
}): Promise<File>
-
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.
-
-
Promise<File>
: A promise that resolves to the file object.
// 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);
Initiate the upload of a file data.
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.
startFileDataUpload(options: {
fileId: string;
versionId: number;
fileType: 'file' | 'signature';
}): Promise<UploadInfo>
-
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'
.
-
-
Promise<UploadInfo>
: A promise that resolves to an object containing upload information, including the AWS S3 URL.
// 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
Check the status of a file data upload.
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.
checkFileDataUploadStatus(options: {
fileId: string;
versionId: number;
fileType: 'file' | 'signature';
}): Promise<FileVersionStatus>
-
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'
.
-
-
Promise<FileVersionStatus>
: A promise that resolves to an object containing the upload status.
// 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);
Get analysis information for a file version.
Retrieve analysis information for a specific file version. This may include various metrics and data about the file.
getFileVersionAnalysis(options: {
fileId: string;
versionId: number;
}): Promise<FileAnalysis>
-
options
(object):-
fileId
(string, required):
The ID of the file. -
versionId
(number, required):
The version number.
-
-
Promise<FileAnalysis>
: A promise that resolves to the file analysis object.
// Example: Get file version analysis
const analysis = await vrchatApi.filesApi.getFileVersionAnalysis({
fileId: 'file_abcdef12-3456-7890-abcd-ef1234567890',
versionId: 1,
});
console.log(analysis);
Get security analysis for a file version.
Retrieve security analysis information for a specific file version. This may include information about any potential security issues.
getFileVersionAnalysisSecurity(options: {
fileId: string;
versionId: number;
}): Promise<FileAnalysis>
- Same as in
getFileVersionAnalysis
-
Promise<FileAnalysis>
: A promise that resolves to the security analysis object.
// Example: Get file version security analysis
const securityAnalysis = await vrchatApi.filesApi.getFileVersionAnalysisSecurity({
fileId: 'file_abcdef12-3456-7890-abcd-ef1234567890',
versionId: 1,
});
console.log(securityAnalysis);
Get standard analysis for a file version.
Retrieve standard analysis information for a specific file version.
getFileVersionAnalysisStandard(options: {
fileId: string;
versionId: number;
}): Promise<FileAnalysis>
- Same as in
getFileVersionAnalysis
-
Promise<FileAnalysis>
: A promise that resolves to the standard analysis object.
// Example: Get file version standard analysis
const standardAnalysis = await vrchatApi.filesApi.getFileVersionAnalysisStandard({
fileId: 'file_abcdef12-3456-7890-abcd-ef1234567890',
versionId: 1,
});
console.log(standardAnalysis);
type File = {
id: string; // File ID
ownerId: string;
name: string;
mimeType: string;
extension?: string;
tags: string[];
versions: FileVersion[];
createdAt: string;
updatedAt: string;
};
type FileVersion = {
version: number;
status: 'waiting' | 'complete' | 'failed';
fileSizeInBytes?: number;
fileMd5?: string;
signatureSizeInBytes: number;
signatureMd5: string;
createdAt: string;
updatedAt: string;
};
type RequestSuccess = {
success: boolean;
};
type UploadInfo = {
url: string; // Pre-signed AWS S3 URL
partNumber: number;
uploadId: string;
headers: { [key: string]: string }; // Additional headers required for the upload
};
type FileVersionStatus = {
status: 'waiting' | 'in_progress' | 'complete' | 'failed';
message?: string;
};
type FileAnalysis = {
// Analysis data specific to the file version
// Structure may vary depending on the analysis type
};
-
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 withfinishFileDataUpload
.
- To upload a file, you typically create a file, create a file version, start uploading data using
-
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.
- The
-
Error Handling:
- Ensure to handle errors appropriately, especially during the upload process, as partial uploads can leave files in an inconsistent state.
-
listFiles
- Retrieve a list of files. -
createFile
- Create a new file object. -
showFile
- Get information about a specific file. -
createFileVersion
- Create a new version for a file. -
deleteFile
- Delete a file object. -
downloadFileVersion
- Download a specific version of a file. -
deleteFileVersion
- Delete a specific version of a file. -
finishFileDataUpload
- Complete the upload of a file data. -
startFileDataUpload
- Initiate the upload of a file data. -
checkFileDataUploadStatus
- Check the status of a file data upload. -
getFileVersionAnalysis
- Get analysis information for a file version. -
getFileVersionAnalysisSecurity
- Get security analysis for a file version. -
getFileVersionAnalysisStandard
- Get standard analysis for a file version.