com.akaxin.proto.core.FileProto Java Examples
The following examples show how to use
com.akaxin.proto.core.FileProto.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ApiFileService.java From wind-im with Apache License 2.0 | 6 votes |
public CommandResponse upload(Command command) { CommandResponse commandResponse = new CommandResponse(); ErrorCode2 errCode = ErrorCode2.ERROR; try { ApiFileUploadProto.ApiFileUploadRequest request = ApiFileUploadProto.ApiFileUploadRequest .parseFrom(command.getParams()); FileProto.File file = request.getFile(); FileProto.FileDesc fileDesc = request.getFileDesc(); FileProto.FileType fileType = file.getFileType(); byte[] content = file.getFileContent().toByteArray(); LogUtils.requestDebugLog(logger, command, request.toString()); String fileId = FileServerUtils.saveFile(content, FilePathUtils.getPicPath(), fileType, fileDesc); ApiFileUploadProto.ApiFileUploadResponse response = ApiFileUploadProto.ApiFileUploadResponse.newBuilder() .setFileId(fileId).build(); commandResponse.setParams(response.toByteArray()); errCode = ErrorCode2.SUCCESS; } catch (Exception e) { errCode = ErrorCode2.ERROR_SYSTEMERROR; LogUtils.requestErrorLog(logger, command, e); } return commandResponse.setErrCode2(errCode); }
Example #2
Source File: ApiFileService.java From openzaly with Apache License 2.0 | 6 votes |
public CommandResponse upload(Command command) { CommandResponse commandResponse = new CommandResponse(); ErrorCode2 errCode = ErrorCode2.ERROR; try { ApiFileUploadProto.ApiFileUploadRequest request = ApiFileUploadProto.ApiFileUploadRequest .parseFrom(command.getParams()); FileProto.File file = request.getFile(); FileProto.FileDesc fileDesc = request.getFileDesc(); FileProto.FileType fileType = file.getFileType(); byte[] content = file.getFileContent().toByteArray(); LogUtils.requestDebugLog(logger, command, request.toString()); String fileId = FileServerUtils.saveFile(content, FilePathUtils.getPicPath(), fileType, fileDesc); ApiFileUploadProto.ApiFileUploadResponse response = ApiFileUploadProto.ApiFileUploadResponse.newBuilder() .setFileId(fileId).build(); commandResponse.setParams(response.toByteArray()); errCode = ErrorCode2.SUCCESS; } catch (Exception e) { errCode = ErrorCode2.ERROR_SYSTEMERROR; LogUtils.requestErrorLog(logger, command, e); } return commandResponse.setErrCode2(errCode); }
Example #3
Source File: ApiFileService.java From openzaly with Apache License 2.0 | 6 votes |
public CommandResponse upload(Command command) { CommandResponse commandResponse = new CommandResponse(); ErrorCode2 errCode = ErrorCode2.ERROR; try { ApiFileUploadProto.ApiFileUploadRequest request = ApiFileUploadProto.ApiFileUploadRequest .parseFrom(command.getParams()); FileProto.File file = request.getFile(); FileProto.FileDesc fileDesc = request.getFileDesc(); FileProto.FileType fileType = file.getFileType(); byte[] content = file.getFileContent().toByteArray(); LogUtils.requestDebugLog(logger, command, request.toString()); String fileId = FileServerUtils.saveFile(content, FilePathUtils.getPicPath(), fileType, fileDesc); ApiFileUploadProto.ApiFileUploadResponse response = ApiFileUploadProto.ApiFileUploadResponse.newBuilder() .setFileId(fileId).build(); commandResponse.setParams(response.toByteArray()); errCode = ErrorCode2.SUCCESS; } catch (Exception e) { errCode = ErrorCode2.ERROR_SYSTEMERROR; LogUtils.requestErrorLog(logger, command, e); } return commandResponse.setErrCode2(errCode); }
Example #4
Source File: FileServerUtils.java From wind-im with Apache License 2.0 | 5 votes |
private static String createFileName(FileProto.FileType type, FileProto.FileDesc fileDesc) { String fileName = System.currentTimeMillis() + UUID.randomUUID().toString().substring(0, 8); if (FileProto.FileType.MESSAGE_VOICE == type) { // 语音 if (fileDesc != null && fileDesc.getLength() > 0) { fileName = fileName + "_" + fileDesc.getLength(); } } else { // 图片 if (fileDesc != null && fileDesc.getWidth() > 0 && fileDesc.getHeight() > 0) { fileName = fileName + "_" + fileDesc.getWidth() + "_" + fileDesc.getHeight(); } } return fileName; }
Example #5
Source File: ApiFileService.java From wind-im with Apache License 2.0 | 5 votes |
public CommandResponse download(Command command) { CommandResponse commandResponse = new CommandResponse(); ErrorCode2 errCode = ErrorCode2.ERROR; try { ApiFileDownloadProto.ApiFileDownloadRequest request = ApiFileDownloadProto.ApiFileDownloadRequest .parseFrom(command.getParams()); // String fileId = request.getFileId(); String reqFileId = request.getFileId(); LogUtils.requestDebugLog(logger, command, request.toString()); if (StringUtils.isNotBlank(reqFileId) && !"null".equals(reqFileId)) { String fileId = reqFileId; if (fileId.startsWith("AKX-") || fileId.startsWith("akx-")) { fileId = fileId.substring(4, fileId.length()); } byte[] imageBytes = FileServerUtils.fileToBinary(FilePathUtils.getPicPath(), fileId); if (imageBytes != null && imageBytes.length > 0) { FileProto.File file = FileProto.File.newBuilder().setFileId(reqFileId) .setFileContent(ByteString.copyFrom(imageBytes)).build(); ApiFileDownloadProto.ApiFileDownloadResponse response = ApiFileDownloadProto.ApiFileDownloadResponse .newBuilder().setFile(file).build(); commandResponse.setParams(response.toByteArray()); errCode = ErrorCode2.SUCCESS; } else { // 获取文件资源失败,文件可能不存在,此时需要抛出异常 errCode = ErrorCode2.ERROR2_FILE_DOWNLOAD; } } else { errCode = ErrorCode2.ERROR_PARAMETER; } } catch (Exception e) { errCode = ErrorCode2.ERROR_SYSTEMERROR; LogUtils.requestErrorLog(logger, command, e); } return commandResponse.setErrCode2(errCode); }
Example #6
Source File: FileServerUtils.java From openzaly with Apache License 2.0 | 5 votes |
private static String createFileName(FileProto.FileType type, FileProto.FileDesc fileDesc) { String fileName = System.currentTimeMillis() + UUID.randomUUID().toString().substring(0, 8); if (FileProto.FileType.MESSAGE_VOICE == type) { // 语音 if (fileDesc != null && fileDesc.getLength() > 0) { fileName = fileName + "_" + fileDesc.getLength(); } } else { // 图片 if (fileDesc != null && fileDesc.getWidth() > 0 && fileDesc.getHeight() > 0) { fileName = fileName + "_" + fileDesc.getWidth() + "_" + fileDesc.getHeight(); } } return fileName; }
Example #7
Source File: ApiFileService.java From openzaly with Apache License 2.0 | 5 votes |
public CommandResponse download(Command command) { CommandResponse commandResponse = new CommandResponse(); ErrorCode2 errCode = ErrorCode2.ERROR; try { ApiFileDownloadProto.ApiFileDownloadRequest request = ApiFileDownloadProto.ApiFileDownloadRequest .parseFrom(command.getParams()); // String fileId = request.getFileId(); String reqFileId = request.getFileId(); LogUtils.requestDebugLog(logger, command, request.toString()); if (StringUtils.isNotBlank(reqFileId) && !"null".equals(reqFileId)) { String fileId = reqFileId; if (fileId.startsWith("AKX-") || fileId.startsWith("akx-")) { fileId = fileId.substring(4, fileId.length()); } byte[] imageBytes = FileServerUtils.fileToBinary(FilePathUtils.getPicPath(), fileId); if (imageBytes != null && imageBytes.length > 0) { FileProto.File file = FileProto.File.newBuilder().setFileId(reqFileId) .setFileContent(ByteString.copyFrom(imageBytes)).build(); ApiFileDownloadProto.ApiFileDownloadResponse response = ApiFileDownloadProto.ApiFileDownloadResponse .newBuilder().setFile(file).build(); commandResponse.setParams(response.toByteArray()); errCode = ErrorCode2.SUCCESS; } else { // 获取文件资源失败,文件可能不存在,此时需要抛出异常 errCode = ErrorCode2.ERROR2_FILE_DOWNLOAD; } } else { errCode = ErrorCode2.ERROR_PARAMETER; } } catch (Exception e) { errCode = ErrorCode2.ERROR_SYSTEMERROR; LogUtils.requestErrorLog(logger, command, e); } return commandResponse.setErrCode2(errCode); }
Example #8
Source File: FileServerUtils.java From openzaly with Apache License 2.0 | 5 votes |
private static String createFileName(FileProto.FileType type, FileProto.FileDesc fileDesc) { String fileName = System.currentTimeMillis() + UUID.randomUUID().toString().substring(0, 8); if (FileProto.FileType.MESSAGE_VOICE == type) { // 语音 if (fileDesc != null && fileDesc.getLength() > 0) { fileName = fileName + "_" + fileDesc.getLength(); } } else { // 图片 if (fileDesc != null && fileDesc.getWidth() > 0 && fileDesc.getHeight() > 0) { fileName = fileName + "_" + fileDesc.getWidth() + "_" + fileDesc.getHeight(); } } return fileName; }
Example #9
Source File: ApiFileService.java From openzaly with Apache License 2.0 | 5 votes |
public CommandResponse download(Command command) { CommandResponse commandResponse = new CommandResponse(); ErrorCode2 errCode = ErrorCode2.ERROR; try { ApiFileDownloadProto.ApiFileDownloadRequest request = ApiFileDownloadProto.ApiFileDownloadRequest .parseFrom(command.getParams()); // String fileId = request.getFileId(); String reqFileId = request.getFileId(); LogUtils.requestDebugLog(logger, command, request.toString()); if (StringUtils.isNotBlank(reqFileId) && !"null".equals(reqFileId)) { String fileId = reqFileId; if (fileId.startsWith("AKX-") || fileId.startsWith("akx-")) { fileId = fileId.substring(4, fileId.length()); } byte[] imageBytes = FileServerUtils.fileToBinary(FilePathUtils.getPicPath(), fileId); if (imageBytes != null && imageBytes.length > 0) { FileProto.File file = FileProto.File.newBuilder().setFileId(reqFileId) .setFileContent(ByteString.copyFrom(imageBytes)).build(); ApiFileDownloadProto.ApiFileDownloadResponse response = ApiFileDownloadProto.ApiFileDownloadResponse .newBuilder().setFile(file).build(); commandResponse.setParams(response.toByteArray()); errCode = ErrorCode2.SUCCESS; } else { // 获取文件资源失败,文件可能不存在,此时需要抛出异常 errCode = ErrorCode2.ERROR2_FILE_DOWNLOAD; } } else { errCode = ErrorCode2.ERROR_PARAMETER; } } catch (Exception e) { errCode = ErrorCode2.ERROR_SYSTEMERROR; LogUtils.requestErrorLog(logger, command, e); } return commandResponse.setErrCode2(errCode); }