Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static File insertFile(Drive service, String title, String description,
- String parentId, String mimeType, String filename) {
- // File's metadata.
- File body = new File();
- body.setTitle(title);
- body.setDescription(description);
- body.setMimeType(mimeType);
- // Set the parent folder.
- if (parentId != null && parentId.length() > 0) {
- body.setParents(
- Arrays.asList(new ParentReference().setId(parentId)));
- }
- // File's content.
- java.io.File fileContent = new java.io.File(filename);
- FileContent mediaContent = new FileContent(mimeType, fileContent);
- try {
- File file = service.files().insert(body, mediaContent).execute();
- // Uncomment the following line to print the File ID.
- // System.out.println("File ID: " + file.getId());
- return file;
- } catch (IOException e) {
- System.out.println("An error occured: " + e);
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement