Fx.file: handle APIs related to files
1. Add watermark to the picture
Fx.file.watermark(<String nPath>, <List words>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| nPath | String | npath of the image |
| words | List | watermark content list |
return type
APIResult
Return value description
Map
Java example
APIResult ret = Fx.file.watermark("N_202003_04_c706c31390b747408bfb5eef3b031f34",Lists.newArrayList("test123","tyrdyz")); //The npath of the file can be found through the find function
Groovy example
def ret = Fx.file.watermark("N_202003_04_c706c31390b747408bfb5eef3b031f34",["test123","tyrdyz"]) //The npath of the file can be found through the find function
2. File upload
Fx.file.uploadFile(<String extensionName>, <Integer fileSize>, <byte[] fileBytes>, <Integer userId>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| extensionName | String | file extension |
| fileSize | Integer | file size |
| fileBytes | byte[] | file content byte array |
| userId | Integer | optional parameter, uploader id |
return type
APIResult
Return value description
Map
Java example
String text = "aaa";
byte[] byteData = Strings.toUTF8Bytes(text);
APIResult ret = Fx.file.uploadFile(".txt", byteData.length, byteData, 1000);
Groovy example
def text = "aaa" as String
def byteData = Strings.toUTF8Bytes(text)
def ret = Fx.file.uploadFile(".txt", byteData.size(), byteData, 1000)
3. Upload the file of the external interface
Fx.file.uploadFileByStream(<Request request>)
Parameter Description
| parameter | type |Description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| request | Request | Network Request Request |
return type
APIResult
Return value description
APIResult
Java example
Request request = Request. builder()
.method("POST")
.url('http://httpbin.org/post')
.timeout(7000)
.retryCount(3)
.body(body)
.build()
APIResult ret = Fx.getFile().uploadFileByStream(request)
Groovy example
//Construct the Request request
Request request = Request. builder()
.method("POST")
.url('http://httpbin.org/post')
.timeout(7000)
.retryCount(3)
.body(body)
.build()
def ret = Fx.file.uploadFileByStream(request)
4. File download returns byte[]
Fx.file.downloadFile(<String nPath>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| nPath | String | nPath of the file |
return type
APIResult
Return value description
FileDownloadData
Java example
APIResult ret = Fx.getFile().downloadFile("N_202007_12_001731386ccf40698523c39744b0161c");
FileDownloadData fileDowloadData = (FileDownloadData) ret. getData();
byte[] fileData = fileDowloadData.getFileData();
String str = Strings.toUTF8String(fileData);
Groovy example
def ret = Fx.file.downloadFile("N_202007_12_001731386ccf40698523c39744b0161c")
def fileDowloadData = ret[1]
def fileData = fileDowloadData['fileData'] as byte[]
def str = Strings.toUTF8String(fileData) as String
5. File download returns InputStream
Fx.file.downloadStream(<String nPath>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| nPath | String | nPath of the file|
return type
APIResult
Return value description
FileDownloadData
Java example
APIResult ret = Fx.getFile().downloadFile("N_202111_29_6eb71dca766944c582b87e6a5213f3a3.docx");
FileDownloadData fileData = (FileDownloadData) ret. getData();
InputStream inputStream = fileData. getInputStream()
Groovy example
def(Boolean err, Object fileData, String msg) = Fx.file.downloadStream("N_202111_29_6eb71dca766944c582b87e6a5213f3a3.docx")
if (err) {
log.info("downloadStream error :" + msg)
} else {
log.info("file data :" + fileData)
}
InputStream inputStream = fileData['inputStream'] as InputStream
log. info(fileData)
6. Package the file and send it to the specified user
Fx.file.packedFile(<List files>, <List userIds>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| files | List | list of build files |
| userIds | List | After one step of packaging is successful, the staff will be reminded |
return type
APIResult
Return value description
Map
Java example
//Define the files that need to be packaged and sent. The parameters are: the packaged file name, the file path under the object (can be queried through the find function), the file suffix, and the storage path in the package after the file is packaged
UserFile file = UserFile.of("File1", "N_201907_31_57a33fb0c999447bb93fa1e4cc6e649d", "jpg", "/image");
List packFileList = Lists. newArrayList(file);
// After packing the files in the fileList, send them to the designated person through the personnel id parameter
final APIResult result = Fx.file.packedFile(packFileList, ["1000"]);
Groovy example
//Define the files that need to be packaged and sent. The parameters are: the packaged file name, the file path under the object (can be queried through the find function), the file suffix, and the storage path in the package after the file is packaged
UserFile file = UserFile.of("File 1","N_201907_31_57a33fb0c999447bb93fa1e4cc6e649d","jpg","/image")
List packFileList = []
packFileList. add(file)
// After packing the files in the fileList, send them to the designated person through the personnel id parameter
final APIResult result = Fx.file.packedFile(packFileList, Lists.newArrayList("1000"));
7. Unauthorized file download, get file download token
Fx.file.createFileShareTokens(<Integer expireMinute>, <List pathList>)
Parameter Description
| parameter | type | description|
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| expireMinute | Integer | Expiration time, in minutes, up to 15 minutes |
| pathList | List | file nPath list |
return type
APIResult
Return value description
Map
Java example
//Get the shareToken of the file without permission
List paths = Lists.newArrayList("N_202102_03_54c5ede542154b748c6f9381d96a1956");
//Get the shareToken of the file without permission
APIResult ret = Fx.file.createFileShareTokens(5, paths);
if (ret. isError()) {
log.info(ret.message());
} else {
log.info(ret.getData());
}
// After obtaining the shareToken, use the following link to download the file:
//http://www.fxiaoke.com/FSC/N/FileShare/DownloadFileBySharedTokenV2?sharedToken=6AA905C78D85C91D796261356AF7467E53719536C4515B3328F7D65FC8476DC777DE783881DF4588EB6B9F0AEEF0F46060EA5D49185941B59C4531F5967FA07B7424EDF8BF20F11F6AE89573CF7F96735EC0284E1F637AE3&name=111.jpg
Groovy example
//Get the shareToken of the file without permission
List paths = ['N_202102_03_54c5ede542154b748c6f9381d96a1956']
//Get the shareToken of the file without permission
def(boolean error, Map data, String errorMessage) = Fx.file.createFileShareTokens(5, paths)
if (error) {
log. info(errorMessage)
} else {
log. info(data)
}
// After obtaining the shareToken, use the following link to download the file:
//http://www.fxiaoke.com/FSC/N/FileShare/DownloadFileBySharedTokenV2?sharedToken=6AA905C78D85C91D796261356AF7467E53719536C4515B3328F7D65FC8476DC777DE783881DF4588EB6B9F0AEEF0F46060EA5D49185941B59C4531F5967FA07B7424EDF8BF20F11F6AE89573CF7F96735EC0284E1F637AE3&name=111.jpg
8. Get attachment pre-signed url
Fx.file.getPresignedUrl(<List paths>, <int expire>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| paths | List | file npath collection |
| expire | int | url validity period (unit: second)|
return type
APIResult
Return value description
List
Java example
List<String>npaths = Lists.newArrayList("N_202207_06_2b51df0dd11043ee9c0ad341742f95bb");
int expire = 100;
APIResult ret = Fx.file.getPresignedUrl(npaths, expire);
if (ret. isError()) {
log.info(ret.message());
} else {
log.info(ret.getData());
}
Groovy example
List npaths = ["N_202207_06_2b51df0dd11043ee9c0ad341742f95bb"]
int expire = 100
def(boolean error, List data, String message) = Fx.file.getPresignedUrl(npaths, expire)
if (error) {
log.info("error: " + message)
} else {
log. info(data)
}
9. Convert to unprivileged npath
Fx.file.convertPath(<String path>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| path | String | file npath |
return type
APIResult
Return value description
Map
Java example
def (Boolean error, Map data, String message) = Fx.file.convertPath("N_202208_01_3628e0ba470b4086aa04dd8f3e93ed5a")
if (error) {
log.info("error :" + message)
} else {
log. info(data)
}
Groovy example
def (Boolean error, Map data, String message) = Fx.file.convertPath("N_202208_01_3628e0ba470b4086aa04dd8f3e93ed5a")
if (error) {
log.info("error :" + message)
} else {
log. info(data)
}
10. Convert the word file on FunShare to pdf
Fx.file.wordToPdf(<String npath>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| npath | String | file npath |
return type
APIResult
Return value description
Map
Java example
def (Boolean error, Map data, String message) = Fx.file.wordToPdf("N_202208_01_3628e0ba470b4086aa04dd8f3e93ed5a")
if (error) {
log.info("error :" + message)
} else {
log. info(data)
}
Groovy example
def (Boolean error, Map data, String message) = Fx.file.wordToPdf("N_202208_01_3628e0ba470b4086aa04dd8f3e93ed5a")
if (error) {
log.info("error :" + message)
} else {
log. info(data)
}