|
|
|
@ -133,35 +133,58 @@ public class NetworkManager {
|
|
|
|
|
conn.setRequestProperty("Accept", "*/*");
|
|
|
|
|
conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
|
|
|
|
|
|
|
|
|
|
request = new DataOutputStream(conn.getOutputStream());
|
|
|
|
|
int request_size = 0;
|
|
|
|
|
|
|
|
|
|
//ask for JSON answer
|
|
|
|
|
request.writeBytes(hyphens + boundary + crlf);
|
|
|
|
|
request.writeBytes("Content-Disposition: form-data; name=\"format\"" + crlf);
|
|
|
|
|
request.writeBytes(crlf);
|
|
|
|
|
request.writeBytes("json" + crlf);
|
|
|
|
|
String answer = hyphens + boundary + crlf;
|
|
|
|
|
answer += "Content-Disposition: form-data; name=\"format\"" + crlf;
|
|
|
|
|
answer += crlf;
|
|
|
|
|
answer += "json" + crlf;
|
|
|
|
|
request_size += answer.length();
|
|
|
|
|
|
|
|
|
|
//ask for storage duration
|
|
|
|
|
request.writeBytes(hyphens + boundary + crlf);
|
|
|
|
|
request.writeBytes("Content-Disposition: form-data; name=\"delete-day\"" + crlf);
|
|
|
|
|
request.writeBytes(crlf);
|
|
|
|
|
request.writeBytes(nbDays + crlf);
|
|
|
|
|
String duration = hyphens + boundary + crlf;
|
|
|
|
|
duration += "Content-Disposition: form-data; name=\"delete-day\"" + crlf;
|
|
|
|
|
duration += crlf;
|
|
|
|
|
duration += nbDays + crlf;
|
|
|
|
|
request_size += duration.length();
|
|
|
|
|
|
|
|
|
|
//setup filename and say that octets follow
|
|
|
|
|
request.writeBytes(hyphens + boundary + crlf);
|
|
|
|
|
request.writeBytes("Content-Disposition: form-data; name=\"file\"; filename=\"" + fileName + "\"" + crlf);
|
|
|
|
|
request.writeBytes("Content-Type: application/octet-stream" + crlf);
|
|
|
|
|
request.writeBytes(crlf);
|
|
|
|
|
request.flush();
|
|
|
|
|
String outputInformations = hyphens + boundary + crlf;
|
|
|
|
|
outputInformations += "Content-Disposition: form-data; name=\"file\"; filename=\"" + fileName + "\"" + crlf;
|
|
|
|
|
outputInformations += "Content-Type: application/octet-stream" + crlf;
|
|
|
|
|
outputInformations += crlf;
|
|
|
|
|
request_size += outputInformations.length();
|
|
|
|
|
|
|
|
|
|
//write image data
|
|
|
|
|
request.write(byteArray);
|
|
|
|
|
request_size += byteArray.length;
|
|
|
|
|
|
|
|
|
|
//finish the format http post packet
|
|
|
|
|
request.writeBytes(crlf);
|
|
|
|
|
request.writeBytes(hyphens + boundary + hyphens + crlf);
|
|
|
|
|
String endHttp = crlf;
|
|
|
|
|
endHttp += hyphens + boundary + hyphens + crlf;
|
|
|
|
|
request_size += endHttp.length();
|
|
|
|
|
|
|
|
|
|
conn.setFixedLengthStreamingMode(request_size);
|
|
|
|
|
|
|
|
|
|
//write data
|
|
|
|
|
request = new DataOutputStream(conn.getOutputStream());
|
|
|
|
|
request.writeBytes(answer);
|
|
|
|
|
request.writeBytes(duration);
|
|
|
|
|
request.writeBytes(outputInformations);
|
|
|
|
|
request.flush();
|
|
|
|
|
//write in loop
|
|
|
|
|
int byteWriten = 0;
|
|
|
|
|
int blockSize = byteArray.length / 100;
|
|
|
|
|
while(byteWriten < byteArray.length) {
|
|
|
|
|
if(byteArray.length - byteWriten < blockSize)
|
|
|
|
|
blockSize = byteArray.length - byteWriten;
|
|
|
|
|
request.write(byteArray,byteWriten,blockSize);
|
|
|
|
|
byteWriten+=blockSize;
|
|
|
|
|
listener.uploadProgress(byteWriten,byteArray.length);
|
|
|
|
|
}
|
|
|
|
|
request.writeBytes(endHttp);
|
|
|
|
|
request.flush();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//get answer
|
|
|
|
|
stream = conn.getInputStream();
|
|
|
|
|
}
|
|
|
|
|