/** * Upload a file from the web * * @return */ public String uploadFromLink() { try { externalUrl = URLDecoder.decode(externalUrl, "UTF-8"); URL url = new URL(externalUrl); title = findFileName(url); File tmp = createTmpFile(); try { StorageController externalController = new StorageController("external"); FileOutputStream fos = new FileOutputStream(tmp); externalController.read(url.toString(), fos, true); Item item = uploadFile(tmp); if (item != null) { UserController uc = new UserController(null); user = uc.retrieve(getUser().getEmail()); ItemController ic = new ItemController(user); ic.create(item, collection.getId()); } externalUrl = ""; } finally { FileUtils.deleteQuietly(tmp); } } catch (Exception e) { logger.error("Error uploading file from link: " + externalUrl, e); fFiles.add(e.getMessage() + ": " + title); } return ""; }
/** Create the {@link Item} for the files which have been uploaded */ private void createItemForFiles() { ItemController ic = new ItemController(user); try { ic.create(itemList, collection.getId()); itemList = new ArrayList<Item>(); } catch (Exception e) { logger.error("Error creating files for upload", e); } }