@Override
	public Response upload(UploadRequest request) throws IOException {
		Mac hmac=null;
		try {
			hmac = Mac.getInstance("HmacSHA256");
		} catch (NoSuchAlgorithmException e) {
			System.err.println("NoSuchAlgorithmException (HmacSHA256 not valid): " + e.getMessage());
			return new HmacErrorResponse("Integrity check failed.");
		} 
		try {
			hmac.init(secretKey);
		} catch (InvalidKeyException e) {
			System.err.println("InvalidKeyException: " + e.getMessage());
			return new HmacErrorResponse("Integrity check failed.");
		}
		hmac.update(request.toString().getBytes());
		
		byte[] computedHash = hmac.doFinal();
		boolean validHash = false;
		if(request.getKey()!=null){
			byte[] receivedHash = Base64.decode(request.getKey());
			validHash = MessageDigest.isEqual(computedHash,receivedHash);
		}
		
		if(validHash){
			if(!FileUtils.writeFile(dir,request.getFilename(),request.getContent())) {
				return new MessageResponse("Cannot write file");
			} else {
				boolean fileExist = false;
				for(FileModel file : fileList){
					//check if the file already exists in fileList
					if(file.getFilename().equals(request.getFilename())){
						//if yes than increase the version by one
						file.setVersion(file.getVersion()+1);
						fileExist = true;
					}
				}
				if(!fileExist){
					//if the file didn't exist, than add it with version number 1
					fileList.add(new FileModel(request.getFilename(),1));
				}
			}
			/*
			//output to check if the versioning is correct
			for(FileModel file : fileList){
				if(file.getFilename().equals(request.getFilename()))
					System.out.println(file.getVersion());
			}*/
			
			return new MessageResponse("Succesfully uploaded file to fileserver on port " + tcpPort);
		} else {
			shell.writeLine(request.toString());
			return new HmacErrorResponse("Integrity check failed in upload Request.");
		}	
	}