@RequestMapping(value = "/addFlashcard", params = {"deckId"}, method = RequestMethod.POST)
	public String addFlashcard(
			@RequestParam("file") MultipartFile file,
			@RequestParam("deckId") int deckId,
			@ModelAttribute Flashcard flashcard, 
			HttpSession session, 
			Model model) {

		if(session.getAttribute("username") == null)
			return "index";

		flashcard.setDeckId(deckId);

		if(!file.isEmpty()) {
			try {
				MessageDigest md = MessageDigest.getInstance("MD5");

				byte[] bytes = file.getBytes();
				byte[] hash = md.digest(bytes);

				File pictureFile = new File("public/pictures/" + hash);

				BufferedOutputStream stream = 
					new BufferedOutputStream( 
						new FileOutputStream(
							pictureFile
						)
					);

				stream.write(bytes);
				stream.close();
	
				System.out.println(pictureFile.getName());
				Database.insertFlashcard(flashcard, pictureFile.getName());
					
				return deck(deckId, session, model);
			} catch(Exception e) {
				return deck(deckId, session, model);	
			}
		}			
		Database.insertFlashcard(flashcard);
		return deck(deckId, session, model);
	}