was.setAccessTokenPair(accessToken);
DropboxAPI<WebAuthSession> api = new DropboxAPI<WebAuthSession>(was);
try {
Entry meta = api.metadata(filePath, 1, null, false, null);
DropboxInputStream streamData = api.getFileStream(filePath, null);
try
{
int bufferSize = 1024;
byte[] buffer = new byte[bufferSize];
ByteArrayOutputStream baos = new ByteArrayOutputStream(bufferSize);
int bytesread = 0;
while(true){
bytesread = streamData.read(buffer);
if (bytesread == -1) break;
baos.write(buffer,0,bytesread);
}
String name = "";
int offset = filePath.lastIndexOf("/");
if (offset!=-1) name = filePath.substring(offset+1);
res.setContentType(meta.mimeType);
if (!"".equals((name)))
res.setHeader("Content-Disposition", "attachment; filename=" + name);
res.setHeader("Cache-Control", "no-cache");
res.setContentLength(baos.size());
ServletOutputStream sos = res.getOutputStream();
baos.writeTo(sos);
sos.flush();
streamData.close();
return null;
}
catch(Exception ex)
{
ex.printStackTrace();