2016-08-02 19 views
2

Ich versuche, eine Datei in den Google Cloud-Speicher hochzuladen, aber es wird eine Ausnahme ausgelöst.Das Hochladen der lokalen Datei in den Google Cloud-Speicher führt zu einem Fehler.

Dies ist mein Code: -

public class MainClass { 
    public static void main(String[] args) { 
     sendFileToGcs(); 
    } 

    private static void sendFileToGcs() 
    { 
      GcsService gcsService = GcsServiceFactory.createGcsService(new RetryParams.Builder() 
      .initialRetryDelayMillis(10) 
      .retryMaxAttempts(10) 
      .totalRetryPeriodMillis(15000) 
      .build()); 
      try{ 
       GcsFileOptions instance = GcsFileOptions.getDefaultInstance(); 
       GcsFilename fileName = new GcsFilename("my-bucket", "myFile"); 
       GcsOutputChannel outputChannel; 
       outputChannel = gcsService.createOrReplace(fileName, instance); 
       File file = new File("audio.mp3"); 

       FileInputStream fis = new FileInputStream(file); 
       InputStream is = fis; 

       copy(is, Channels.newOutputStream(outputChannel)); 
       fis.close(); 
      }catch(IOException e){} 
      while(true){} 

    } 

    private static void copy(InputStream input, OutputStream output) throws IOException { 
     final int BUFFER_SIZE = 2 * 1024 * 1024; 
      try { 
       byte[] buffer = new byte[BUFFER_SIZE]; 
       int bytesRead = input.read(buffer); 
       while (bytesRead != -1) { 
       output.write(buffer, 0, bytesRead); 
       bytesRead = input.read(buffer); 
       } 
      } finally { 
       input.close(); 
       output.close(); 
      } 
      } 

} 

Ausnahmedetails: -

> Aug 02, 2016 3:41:01 PM 
> com.google.appengine.tools.cloudstorage.RetryHelper doRetry INFO: 
> RetryHelper(14.86 ms, 1 attempts, 
> [email protected]6): 
> Attempt #1 failed [java.io.IOException: 
> java.lang.NullPointerException], sleeping for 12 ms Aug 02, 2016 
> 3:41:01 PM com.google.appengine.tools.cloudstorage.RetryHelper doRetry 
> INFO: RetryHelper(59.97 ms, 2 attempts, 
> [email protected]6): 
> Attempt #2 failed [java.io.IOException: 
> java.lang.NullPointerException], sleeping for 16 ms Aug 02, 2016 
> 3:41:01 PM com.google.appengine.tools.cloudstorage.RetryHelper doRetry 
> INFO: RetryHelper(77.05 ms, 3 attempts, 
> [email protected]6): 
> Attempt #3 failed [java.io.IOException: 
> java.lang.NullPointerException], sleeping for 32 ms Aug 02, 2016 
> 3:41:01 PM com.google.appengine.tools.cloudstorage.RetryHelper doRetry 
> INFO: RetryHelper(110.4 ms, 4 attempts, 
> [email protected]6): 
> Attempt #4 failed [java.io.IOException: 
> java.lang.NullPointerException], sleeping for 82 ms Aug 02, 2016 
> 3:41:01 PM com.google.appengine.tools.cloudstorage.RetryHelper doRetry 
> INFO: RetryHelper(193.5 ms, 5 attempts, 
> [email protected]6): 
> Attempt #5 failed [java.io.IOException: 
> java.lang.NullPointerException], sleeping for 159 ms Aug 02, 2016 
> 3:41:01 PM com.google.appengine.tools.cloudstorage.RetryHelper doRetry 
> INFO: RetryHelper(353.7 ms, 6 attempts, 
> [email protected]6): 
> Attempt #6 failed [java.io.IOException: 
> java.lang.NullPointerException], sleeping for 394 ms Aug 02, 2016 
> 3:41:01 PM com.google.appengine.tools.cloudstorage.RetryHelper doRetry 
> INFO: RetryHelper(750.2 ms, 7 attempts, 
> [email protected]6): 
> Attempt #7 failed [java.io.IOException: 
> java.lang.NullPointerException], sleeping for 640 ms Aug 02, 2016 
> 3:41:02 PM com.google.appengine.tools.cloudstorage.RetryHelper doRetry 
> INFO: RetryHelper(1.393 s, 8 attempts, 
> [email protected]6): 
> Attempt #8 failed [java.io.IOException: 
> java.lang.NullPointerException], sleeping for 1547 ms Aug 02, 2016 
> 3:41:04 PM com.google.appengine.tools.cloudstorage.RetryHelper doRetry 
> INFO: RetryHelper(2.941 s, 9 attempts, 
> [email protected]6): 
> Attempt #9 failed [java.io.IOException: 
> java.lang.NullPointerException], sleeping for 2694 ms Exception in 
> thread "main" 
> com.google.appengine.tools.cloudstorage.RetriesExhaustedException: 
> RetryHelper(5.637 s, 10 attempts, 
> [email protected]6): 
> Too many failures, giving up at 
> com.google.appengine.tools.cloudstorage.RetryHelper.doRetry(RetryHelper.java:127) 
> at 
> com.google.appengine.tools.cloudstorage.RetryHelper.runWithRetries(RetryHelper.java:166) 
> at 
> com.google.appengine.tools.cloudstorage.RetryHelper.runWithRetries(RetryHelper.java:156) 
> at 
> com.google.appengine.tools.cloudstorage.GcsServiceImpl.createOrReplace(GcsServiceImpl.java:70) 
> at MainClass.sendApkToFirebase(MainClass.java:33) at 
> MainClass.main(MainClass.java:19) Caused by: java.io.IOException: 
> java.lang.NullPointerException at 
> com.google.appengine.tools.cloudstorage.dev.LocalRawGcsService$BlobStorageAdapter.getInstance(LocalRawGcsService.java:186) 
> at 
> com.google.appengine.tools.cloudstorage.dev.LocalRawGcsService$BlobStorageAdapter.access$000(LocalRawGcsService.java:109) 
> at 
> com.google.appengine.tools.cloudstorage.dev.LocalRawGcsService.ensureInitialized(LocalRawGcsService.java:194) 
> at 
> com.google.appengine.tools.cloudstorage.dev.LocalRawGcsService.beginObjectCreation(LocalRawGcsService.java:249) 
> at 
> com.google.appengine.tools.cloudstorage.dev.LocalRawGcsService.beginObjectCreation(LocalRawGcsService.java:92) 
> at 
> com.google.appengine.tools.cloudstorage.GcsServiceImpl$1.call(GcsServiceImpl.java:74) 
> at 
> com.google.appengine.tools.cloudstorage.GcsServiceImpl$1.call(GcsServiceImpl.java:70) 
> at 
> com.google.appengine.tools.cloudstorage.RetryHelper.doRetry(RetryHelper.java:108) 
> ... 5 more Caused by: java.lang.NullPointerException at 
> com.google.appengine.tools.cloudstorage.dev.LocalRawGcsService$BlobStorageAdapter.<init>(LocalRawGcsService.java:123) 
> at 
> com.google.appengine.tools.cloudstorage.dev.LocalRawGcsService$BlobStorageAdapter.getInstance(LocalRawGcsService.java:184) 
> ... 12 more 
+0

Ich habe genau den gleichen Fehler jetzt. Wenn ich eine Lösung finde, werde ich Sie wissen lassen. –

+0

Das wäre gut. –

Antwort