Applet File Management
1. Convert finfile paths to absolute paths
In some scenarios, we get the file path of the applet and can't get the file data, so we can use this method to convert it to absolute path.
For example, when using the forwarding function of the applet, the returned image path is the applet file path, so you can use this method to convert it to absolute path, and then get the image data and start the third-party sharing. For example, in the custom api, you can pass the parameter of applet file path, and the host app can get the file data after converting it to absolute path with this method.
objectivec
/**
Converts the file path to an absolute path
If it is a network file path, it is returned directly.
If it is a path in the phizclip, such as finfile://tmp_fdfdkfjdkfjdkjfdkjf.jpg, it will be converted to a local absolute path
If it is a file path in a small package, such as image/xxx.jpg, it will also be converted to an absolute path
In other cases, the incoming path is returned
@param path File path
@return The absolute path to the file
*/
- (NSString *)fat_absolutePathWithPath:(NSString *)path;Example code:
objectivec
NSString *finfilePath = @"finfile://tmp_7C82E6C26B7627334E88355E9D286621.mp4";
NSString *path = [[FATClient sharedClient] fat_absolutePathWithPath:filePath];2. Save the file to the current applet temporary directory
The SDK supports saving files natively to the applet's cache directory and then returning the local path to the file for use by the applet.
objectivec
/**
Save the file to the cache path of the applet
@param fileData The binary data of the file
@param fileName file name, you need to ensure that the file name is unique, otherwise it may be overwritten
@return The local path of the file, for example: finfile://tmp_fdfdkfjdkfjdkjfdkjf.jgp
*/
- (NSString *)saveFile:(NSData *)fileData fileName:(NSString *)fileName;