Appearance
Mini Program File Management
1. Convert finfile paths to absolute paths
In some scenarios, we get the file path of the mini program 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 mini program, the returned image path is the mini program 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 mini program file path, and the host app can get the file data after converting it to absolute path with this method.
objective-c
/**
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 Mini Program, 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:
objective-c
NSString *finfilePath = @"finfile://tmp_7C82E6C26B7627334E88355E9D286621.mp4";
NSString *path = [[FATClient sharedClient] fat_absolutePathWithPath:filePath];
2. Save the file to the current mini program temporary directory
The SDK supports saving files natively to the mini program's cache directory and then returning the local path to the file for use by the mini program.
objective-c
/**
Save the file to the cache path of the mini program
@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;