return;
}
}
List<BlobKey> blobs = blobstoreService.getUploads(req).get("myFile");
BlobKey blobKey = blobs.get(0);
if (null == blobKey) {
sendError(res, "無法正常儲存上傳的檔案");
return;
}
ImagesService imagesService = ImagesServiceFactory.getImagesService();
ServingUrlOptions servingOptions = ServingUrlOptions.Builder.withBlobKey(blobKey);
String servingUrl = imagesService.getServingUrl(servingOptions);
res.setStatus(HttpServletResponse.SC_OK);
res.setContentType("application/json");
// 二種方式都能存取上傳的圖檔
JSONObject json = new JSONObject();
// json.put("serving_url", servingUrl);
// json.put("blob_key", blobKey.getKeyString());
// json.put("direct_url", "/serve?blob_key=" + blobKey.getKeyString());
// 儲存在db的動作
DeviceUpload du = new DeviceUpload();
du.setDevID(devID);
du.setMySerial(mySerial);
du.setServing_url(servingUrl);
du.setBlob_key(blobKey.getKeyString());
du.setAddTime(CTCommon.getNowTime());
du_service.add(du);
log.info("新增一筆設備上傳記錄:" + JSON.toJSONString(du));
// 直接新增message info到db