1
我正在上傳文檔併成功存儲在谷歌驅動器上。現在我只想獲取文件的縮略圖以在下載鏈接處顯示。請告訴我我是怎麼做的?這是我用於上傳文件的控制器代碼。如何在我的項目中顯示縮略圖圖像時,我在谷歌驅動器上存儲圖像
'`@RequestMapping(value = "/upload", method = RequestMethod.POST)
public ModelAndView uploadFile(@RequestParam(value = "ddid", required = true) Integer ddid,
@RequestParam(value = "catageryId", required = true) Integer catageryId,
@RequestParam(value = "document", required = true) GMultipartFile document[], HttpServletRequest request, HttpServletResponse resp) {
DdeDriveDocuments ddeDriveDocuments = new DdeDriveDocuments();
if (ServletFileUpload.isMultipartContent(request) && document != null) {
for (GMultipartFile gdocument : document) {
try {
boolean user = true;
List<DdeDriveDocuments> dds = ddeDriveDocumentsService.fatchData(ddid, catageryId);
for (DdeDriveDocuments file : dds) {
System.out.println(file.getDocument_name());
if (file.getDocument_name().equals(gdocument.getOriginalFilename())) {
user = false;
}
}
if (user == true) {
ddeDriveDocuments
.setDocument_name((gdocument.getName() != null ? gdocument.getOriginalFilename() : ""));
System.out.println(gdocument.getOriginalFilename());
ddeDriveDocuments.setDocument_created(new Date());
ddeDriveDocuments.setCatagery_id(catageryId);
ddeDriveDocuments.setDd_id(ddid);
ddeDriveDocuments.setDd_uuid(GeneralUtil.getUUID());
Lawyer googleAuthToken = lawyerService
.getAuthorisedUserToken(Configurator.getInstance().getDriveAccountEmail());
if (googleAuthToken != null) {
// upload file in drive
if (ServletFileUpload.isMultipartContent(request) && document != null) {
// It's value either we need to get from form.
String description = "Testing";
File file = DriveService.uploadDocumentToDrive(googleAuthToken, gdocument,
ddeDriveDocuments.getDocument_name(), description);
File thumFile = DriveService.getFileById(googleAuthToken, file.getId());
System.out.println("thab url"+thumFile.getThumbnail());
System.out.println(file.getThumbnailLink());
if (file != null) {
ddeDriveDocuments.setDocument_drive_id(file.getId());
ddeDriveDocuments.setThumburl(thumFile.getThumbnailLink());
ddeDriveDocuments = ddeDriveDocumentsService.create(ddeDriveDocuments);
}
}
} else {
System.out.println("Autorised token not available for configured drive account.");
}
}
else {
System.out.println("wroung Input");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
return new ModelAndView("redirect:/al/lawyer/ddfiles/" + ddid + "/" + catageryId);
}`'
好的,你可以建議我如何緩存縮略圖在我的應用程序。或者你可以給我提供任何我使用gmultipart文件的例子。 –
我上面已經上傳了一些代碼。 –
@AbhishekSharma上面的代碼適用於上傳,這是第一步。現在您需要獲取上傳文件的信息。有一個如何在這裏執行的示例:https://developers.google.com/drive/v2/reference/files/get。緩存最簡單的方法是簡單地下載縮略圖並將其保存爲「fileid_thumb」somwhere,並在下一個請求時檢查在實際請求縮略圖之前是否存在此文件。 – konqi