Converting wxfile path to absolute path
In some scenarios, you may need to convert a mini program file path to an absolute path to access the file data.
For example, when using the mini program's forwarding feature, the returned image path is a mini program file path. You can convert it to an absolute path to access the image data and then initiate third-party sharing. Similarly, in custom APIs, you can pass the mini program file path as a parameter, and the host app can convert it to an absolute path to access the file data.
Sample code:
TMAFileManager *fm = [[TMFMiniAppSDKManager sharedInstance] getFileManagerWithAppID:appInfo.appId];
NSString *filePath = [fm translateWxfilePathToAbsolutePath:wxPath];
Converting absolute path to wxfile path
The SDK supports converting file paths created in the mini program's cache directory to mini program file paths for internal use.
Sample code:
TMAFileManager *fm = [[TMFMiniAppSDKManager sharedInstance] getFileManagerWithAppID:appInfo.appId];
NSString *tmpPath = [fm createMediaTmpPathWithFileName:@"a.pdf" type:TMATmpPathTypeFile needTimestamp:YES];
NSString *wxPath = [fm translateAnyPathToWxfilePath:tmpPath];
Creating files in the mini program temporary directory
The SDK supports creating files in the mini program's cache directory natively.
Sample code:
TMAFileManager *fm = [[TMFMiniAppSDKManager sharedInstance] getFileManagerWithAppID:appInfo.appId];
NSString *tmpPath = [fm createMediaTmpPathWithFileName:@"a.pdf" type:TMATmpPathTypeFile needTimestamp:YES];
Was this page helpful?