1 package com.introlab.rtabmap;
3 import java.io.BufferedReader;
6 import java.io.FileInputStream;
7 import java.io.IOException;
8 import java.io.InputStreamReader;
9 import java.io.OutputStream;
10 import java.io.OutputStreamWriter;
11 import java.io.PrintWriter;
12 import java.net.HttpURLConnection;
14 import java.net.URLConnection;
15 import java.util.ArrayList;
16 import java.util.List;
45 boundary =
"===" + System.currentTimeMillis() +
"===";
47 URL
url =
new URL(requestURL);
48 httpConn = (HttpURLConnection)
url.openConnection();
52 httpConn.setRequestProperty(
"Content-Type",
"multipart/form-data; boundary=" +
boundary);
53 httpConn.setRequestProperty(
"Authorization",
"Bearer " + token);
81 String fileName = uploadFile.getName();
84 "Content-Disposition: form-data; name=\"" + fieldName
85 +
"\"; filename=\"" + fileName +
"\"")
89 + URLConnection.guessContentTypeFromName(fileName))
95 FileInputStream inputStream =
new FileInputStream(uploadFile);
96 byte[]
buffer =
new byte[4096];
98 while ((bytesRead = inputStream.read(
buffer)) != -1) {
124 public List<String>
finish() throws IOException {
125 List<String> response =
new ArrayList<String>();
132 int status =
httpConn.getResponseCode();
134 BufferedReader
reader =
new BufferedReader(
new InputStreamReader(
137 while ((line =
reader.readLine()) !=
null) {
143 throw new IOException(
"Server returned non-OK status: " + status +
", msg: " +
httpConn.getResponseMessage());