A powerful JavaScript library for parsing DJI txt logs with support for all log versions and encryptions.
- Parse records and extract embedded images from DJI logs
- Normalize records across different log versions for a consistent frame format
- Support for all log versions, including encrypted logs (version 13+)
- Easy-to-use API for accessing general data, frames, and raw records
- Ability to fetch and store keychains for offline use with encrypted logs
- Browser support (See Limitations)
To install the DJI Log Parser library, use npm:
npm install dji-log-parser-js
Or using yarn:
yarn add dji-log-parser-js
Starting with version 13, log records are AES encrypted and require a specific keychain for decryption. This keychain must be obtained from DJI using their API. An apiKey is necessary to access the DJI API.
Once keychains are retrieved from DJI API, they can be stored along with the original log for further offline use.
To acquire an apiKey, follow these steps:
- Visit DJI Developer Technologies and log in.
- Click
CREATE APP
, chooseOpen API
as the App Type, and provide the necessary details likeApp Name
,Category
, andDescription
. - After creating the app, activate it through the link sent to your email.
- On your developer user page, find your app's details to retrieve the ApiKey (labeled as the SDK key).
Initialize a DJILog
instance from a byte buffer to access version information and metadata:
import { DJILog } from "dji-log-parser-js";
import { readFileSync } from "fs";
const buffer = readFileSync("./DJIFlightRecord.txt");
const parser = new DJILog(buffer);
Html
<input type="file" id="file" name="file" />
Javascript
import { DJILog } from "dji-log-parser-js";
document
.getElementById("file")
.addEventListener("change", handleFileSelect, false);
function handleFileSelect(event) {
const file = event.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = async function (e) {
const bytes = new Uint8Array(e.target.result);
const parser = new DJILog(bytes);
};
reader.readAsArrayBuffer(file);
}
}
General data are not encrypted and can be accessed from the parser for all log versions:
// Print the log version
console.log("Version:", parser.version);
// Print the log details section
console.log("Details:", parser.details);
For logs version 13 and later, keychains must be retrieved from the DJI API to decode the records:
// Replace `__DJI_API_KEY__` with your actual apiKey
const keychains = await parser.fetchKeychains("__DJI_API_KEY__");
Keychains can be retrieved once, serialized, and stored along with the log file for future offline use.
Decrypt frames based on the log file version.
A Frame
is a standardized representation of log data, normalized across different log versions.
It provides a consistent and easy-to-use format for analyzing and processing DJI log information.
For versions prior to 13:
const frames = parser.frames();
For version 13 and later:
const frames = parser.frames(keychains);
Decrypt raw records based on the log file version. For versions prior to 13:
const records = parser.records();
For version 13 and later:
const records = parser.records(keychains);
This library requires fetch
to be globally available (Node >= 18.0) for retrieving keychains from the DJI endpoint.
For older Node versions, you can manually retrieve the keychains using an alternative method, such as Axios. The library conveniently provides the necessary data for making keychains request through the parser.keychainsRequest()
function.
Here’s an example with Axios:
const axios = require("axios");
const body = JSON.stringify(parser.keychainsRequest());
const response = await axios.post(
"https://dev.dji.com/openapi/v1/flight-records/keychains",
body,
{
headers: {
"Content-Type": "application/json",
"Api-Key": "your_api_key_here",
},
}
);
const keychains = response.data.data;
The DJI Keychain API endpoint does not support CORS (Cross-Origin Resource Sharing). This limitation is acknowledged in an open issue on GitHub: https://github.com/dji-sdk/FlightRecordParsingLib/issues/31
While awaiting a resolution, a temporary workaround involves using a CORS proxy server. Below is an example utilizing a free proxy server: https://github.com/Zibri/cloudflare-cors-anywhere
// Replace `__DJI_API_KEY__` with your actual apiKey
// Don't use this in production, only for testing purpose
const keychains = await parser.fetchKeychains(
"__DJI_API_KEY__",
"https://test.cors.workers.dev/?https://dev.dji.com/openapi/v1/flight-records/keychains"
);
dji-log-parser-js is available under the MIT license. See the LICENSE.txt file for more info.