|
@@ -21,6 +21,13 @@ import edu.nju.entities.TestCase;
|
|
|
import edu.nju.service.ExtraService;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.net.URL;
|
|
|
+import java.io.BufferedInputStream;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.OutputStream;
|
|
|
+import java.net.HttpURLConnection;
|
|
|
+import java.net.URLConnection;
|
|
|
+
|
|
|
@Controller
|
|
|
@RequestMapping(value = "/extra")
|
|
|
@CrossOrigin(origins = "*", maxAge = 3600, allowCredentials = "true")
|
|
@@ -195,6 +202,69 @@ public class ExtraController {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ *
|
|
|
+ * @param file 文件oss的url
|
|
|
+ * @param file_name
|
|
|
+ * @param paper_type
|
|
|
+ * @param case_id
|
|
|
+ * @param test_type
|
|
|
+ * @param description
|
|
|
+ * @param app_name
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/uploadExamUrl", method = RequestMethod.POST)
|
|
|
+ @ResponseBody
|
|
|
+ public String uploadExamUrl(String file, String file_name, String paper_type,
|
|
|
+ String case_id, String test_type, String description, String app_name) {
|
|
|
+ try {
|
|
|
+
|
|
|
+ File dest = new File("/Users/hannatao/Downloads/" + file_name);
|
|
|
+ if(!dest.getParentFile().exists()) { dest.getParentFile().mkdirs(); }
|
|
|
+
|
|
|
+
|
|
|
+ URL url = new URL(file);
|
|
|
+
|
|
|
+ URLConnection urlConnection = url.openConnection();
|
|
|
+
|
|
|
+ HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection;
|
|
|
+
|
|
|
+ httpURLConnection.setConnectTimeout(1000*5);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ httpURLConnection.setRequestProperty("Charset", "UTF-8");
|
|
|
+
|
|
|
+ httpURLConnection.connect();
|
|
|
+
|
|
|
+ int fileLength = httpURLConnection.getContentLength();
|
|
|
+
|
|
|
+
|
|
|
+ URLConnection con = url.openConnection();
|
|
|
+ BufferedInputStream bin = new BufferedInputStream(httpURLConnection.getInputStream());
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ OutputStream out = new FileOutputStream(dest);
|
|
|
+ int size = 0;
|
|
|
+ int len = 0;
|
|
|
+ byte[] buf = new byte[2048];
|
|
|
+ while ((size = bin.read(buf)) != -1) {
|
|
|
+ len += size;
|
|
|
+ out.write(buf, 0, size);
|
|
|
+ }
|
|
|
+
|
|
|
+ bin.close();
|
|
|
+ out.close();
|
|
|
+ String json = extraService.saveExam(case_id, dest.getPath(), app_name, paper_type, test_type, description);
|
|
|
+ return json;
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
* 47.99.140.117:9001/Bug/api/extra/getExamList
|
|
|
*
|
|
|
* @return 200 成功; 500 失败
|