Created
November 28, 2016 01:20
-
-
Save pnakibar/62e8194eb2fa046ae98784f928d288e7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package beerzeit.utils; | |
import org.apache.commons.io.IOUtils; | |
import org.primefaces.model.DefaultStreamedContent; | |
import org.primefaces.model.StreamedContent; | |
import org.primefaces.model.UploadedFile; | |
import java.io.*; | |
/** | |
* Created by pedro on 27/11/16. | |
*/ | |
public class AvatarStorage { | |
private static final String FILES_DIR = "/home/pedro/DESENVOLVIMENTOWEB/uploads/"; | |
public static String save(UploadedFile avatar, String filename) throws IOException { | |
InputStream avatarIS = avatar.getInputstream(); | |
String[] split = avatar.getFileName().split("\\."); | |
String format = split[split.length - 1]; | |
String finalFileName = filename + "." + format; | |
File f = new File(FILES_DIR, filename); | |
f.createNewFile(); | |
OutputStream avatarOS = new FileOutputStream(f); | |
IOUtils.copy(avatarIS, avatarOS); | |
return FILES_DIR + filename; | |
} | |
public static StreamedContent showFile(String filename) throws FileNotFoundException { | |
File f = new File(FILES_DIR, filename); | |
OutputStream os = new FileOutputStream(f); | |
return new DefaultStreamedContent(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment