@Override public String upload(InputStream is, String filename, String contentType, long length) throws IOException { ObjectMetadata meta = new ObjectMetadata(); meta.setContentLength(length); meta.setContentType(contentType); meta.setCacheControl("max-age: " + 3600 * 1000 * 48); meta.setContentEncoding("UTF-8"); meta.setLastModified(new Date()); client.putObject(name, filename, is, meta); return filename; }
@RequestMapping("uploadFile.do") public @ResponseBody Object uploadObject( @RequestParam("source") CommonsMultipartFile mFile, @ModelAttribute UploadSource uploadSource) { // System.out.println(mFile); try { // Set the expired time to one hour later. uploadSource.setInputStream(mFile.getInputStream()); ObjectMetadata objectMetaData = new ObjectMetadata(); objectMetaData.setContentType(mFile.getContentType()); objectMetaData.setContentLength(mFile.getFileItem().getSize()); uploadSource.setObjectMetaData(objectMetaData); ossService.uploadObject(uploadSource); // Thread.sleep(2000); return genSuccessResponse("", null); } catch (Exception e) { e.printStackTrace(); return genFailureResponse(e.getMessage()); } }