volume upload: added post request parser to get the file content

This commit is contained in:
Rajani Karuturi 2015-01-17 04:04:55 +05:30
parent 5e1bd634a4
commit ef0c5d35cf
1 changed files with 40 additions and 4 deletions

View File

@ -25,6 +25,8 @@ import static org.apache.commons.lang.StringUtils.substringAfterLast;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@ -32,7 +34,9 @@ import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.InterruptedIOException;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.net.InetAddress;
import java.net.InetSocketAddress;
@ -2681,11 +2685,43 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
} else {
data = EntityUtils.toByteArray(entity);
}
//call handle upload method.
//handleuplod();
s_logger.info(new String(data));
//TODO: post request is available in data. Need to parse and save file.
InputStream is = new ByteArrayInputStream(data);
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
ByteArrayOutputStream output = new ByteArrayOutputStream();
String currentLine = reader.readLine();
String boundary = currentLine.replace("-","");
while(reader.ready()) {
currentLine = reader.readLine();
if (currentLine.contains("Content-Type: ")) {
// File Content here
reader.readLine();
String prevLine = reader.readLine();
currentLine = reader.readLine();
//writing the data to a output stream
while (true) {
if (currentLine.contains(boundary)) {
output.write(prevLine.getBytes());
break;
}
else {
output.write(currentLine.getBytes());
}
prevLine = currentLine;
currentLine = reader.readLine();
}
}
}
//call handle upload method.
//TODO: get entityid, absolute path from metadata and filename from post data
handleuplod(1, null, "file", output.size(), output.toByteArray());
s_logger.error(new String(data));
httpResponse.setEntity(new StringEntity("upload successful"));
}