2013-05-15 30 views
6

Tôi có nội dung phương tiện như trong luồng byte và tôi đang cố tải lên luồng đó trong Google Drive.Tải luồng byte lên Google Drive qua luồng đầu vào

Code:

private static String writeToGoogleDrive(Drive service, String title, 
     String description, String parentId, String mimeType, 
     final byte[] filename) throws IOException { 
    String URL=""; 
    File body = new File(); 
    body.setTitle(title); 
    body.setDescription(description); 
    body.setMimeType(mimeType); 




    if (parentId != null && parentId.length() > 0) { 
     body.setParents(Arrays.asList(new ParentReference().setId(parentId))); 
    } 
    try { 

    File file= service.files().insert(body, new AbstractInputStreamContent("") { 

      @Override 
      public boolean retrySupported() { 
       // TODO Auto-generated method stub 
       return false; 
      } 

      @Override 
      public long getLength() throws IOException { 
       // TODO Auto-generated method stub 
       System.out.println("the value of the length of the file is "+filename.length); 
       return filename.length; 
      } 

      @Override 
      public InputStream getInputStream() throws IOException { 
       // TODO Auto-generated method stub 
       return new ByteArrayInputStream(filename); 
      } 

     }).execute(); 

Ngoại lệ: nó chỉ nói null, nhưng tôi không biết gì (mà) null là.

Trả lời

4

Bạn có thể thử một cái gì đó như thế này:

file = service.files().insert(body, new InputStreamContent(mimeType, 
new ByteArrayInputStream(filename))).execute(); 
+0

ở đây, nơi dịch vụ được xác định? –

Các vấn đề liên quan