Google Drive SDK (Java) service account upload file and access from browser -


As I have mentioned in the headline, I am uploading a gzip file from my Java program as below: /p>

  Enter a private static file (drive service, string title, string description, string parent ID, string mimetype, string filename) {// file's metadata. File body = new file (); Body.setTitle (title); Body.setDescription (description); Body.setMimeType (mimetype); // Set the original folder. If (parentId! = Null & parentId.length ()> 0) {body.setParents (arrays.asList) (new parent reference. SetId (parentId)); } // File contents Java.io.file fileSource = new java.io.file (file name); FileContent Media Content = New File Resource (mimetype, file resource); Try {File file = service.files (). Insert (body, media content) .execute (); Return file; } Hold (IOException e) {System.out.println ("An error occurred:" + E); Return tap; }} Public stable drive getDriveService () throws GeneralSecurityException, IOException, URISyntaxException {HttpTransport httpTransport = new NetHttpTransport (); Jacksonfactor jasonfactor = new jacksonfactor (); GoogleCredential Credential = New GoogleCredential.Builder () SetTransport (httpTransport) .setJsonFactory () .setServiceAccountId (SERVICE_ACCOUNT_EMAIL) .setServiceAccountScopes (Arrays.asList (DriveScopes.DRIVE)) .setServiceAccountPrivateKeyFromP12File (new java.io.file (SERVICE_ACCOUNT_PKCS12_FILE_PATH)). Construction (); Drive Service = New Drive. Builder (httpTransport, jsonfactory, null) .setHttpRequestInitializer (Credential) .setApplicationName ("Svn Backup") .build (); Return service; } Public Zero Main () {drive drive service = getDriveService (); // Enter a file system.out.printline (new local time) ToString ("dd.MM.yyyy HH: mm: ss") + ":" + "Trying to upload to Google Drive ..") ; File file = insert file (drive service, new local time). ToString ("dd_MM_yyyy_HH_mm_ss"), "", blank, "app / x-gzip", args [1] + ".gz"); System.out.println (new localetetime). ToString ("dd.mm.yyyy hh: mm: ss" + ":" + "file:" + file); System.out.println ("Successfully uploaded"); }  

This works perfectly, because I can access my files with files (.list () command, Can not see the applications in Google Drive either because of the https://drive.google.com/

? What should I do?


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -