Java Code Examples for com.akaxin.proto.site.ApiFileUploadProto

The following examples show how to use com.akaxin.proto.site.ApiFileUploadProto. These examples are extracted from open source projects. 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 Project: wind-im   Source File: ApiFileService.java    License: Apache License 2.0 6 votes vote down vote up
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 Project: openzaly   Source File: ApiFileService.java    License: Apache License 2.0 6 votes vote down vote up
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 Project: openzaly   Source File: ApiFileService.java    License: Apache License 2.0 6 votes vote down vote up
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);
}