I have an existing File object, created during my program. How can I use the drive API to upload this to a specific folder?

I understand it's something like this:

String folderId = "0BwwA4oUTeiV1TGRPeTVjaWRDY1E";
File fileMetadata = new File();
java.io.File filePath = new java.io.File("files/photo.jpg");
FileContent mediaContent = new FileContent("image/jpeg", filePath);
File file = driveService.files().create(fileMetadata, mediaContent)
.setFields("id, parents")
 System.out.println("File ID: " + file.getId());

But (1) how do I create the driveService object, and (2) how do I replicate the above if I want to use a File object generated in my program, not one that exists on my computer?

Related posts

Recent Viewed