-
-
Save dcode/f879a62574e94a2265ae to your computer and use it in GitHub Desktop.
This file contains 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
object Download extends Controller { | |
import org.apache.commons.logging.Log | |
import org.apache.hadoop.conf.Configuration | |
import org.apache.hadoop.fs._ | |
import java.io.InputStream | |
import java.net.URI | |
import java.net.URLDecoder | |
def download(filename: String) = { | |
try { | |
val uri = play.configuration("hadoop.uri") // "hadoop.uri=hdfs://hadoop" in conf/application.conf file | |
val conf = new Configuration() | |
val hdfs = FileSystem.get(URI.create(uri), conf) | |
response.setHeader("Content-type", "application/force-download") | |
response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"") | |
// response.setHeader("Content-Length", filesize + ""); | |
response.direct = hdfs.open(new Path(filename)).asInstanceOf[java.io.InputStream] | |
} | |
catch { | |
case e: Exception => Logger.error(e, "Couldn't get file from Hadoop by the given filename") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment