2016-04-14 23 views
0

Bu benim dosyanın inputStream gelen "AbstractInputStreamContent" oluşturmak nasıl:Sürücü V3 API: java.lang.IllegalArgumentException

final Long length = Long.valueOf(filesData.get(uploadedFileName).get("size")).longValue(); 
    final InputStream fileStream = item.openStream(); //FileItemStream item 
    AbstractInputStreamContent fileContent = new AbstractInputStreamContent(uploadedFileMimeType) { 
     @Override 
     public boolean retrySupported() { 
      return false; 
     } 
     @Override 
     public long getLength() throws IOException { 
      return length; 
     } 
     @Override 
     public InputStream getInputStream() throws IOException { 
      return fileStream; 
     } 
    }; 

Ve "InputStreamContent":

InputStreamContent fileContent = new InputStreamContent(uploadedFileMimeType, item.openStream()); 
fileContent.setLength(Long.valueOf(filesData.get(uploadedFileName).get("size")).longValue()); 

eski dosyasını değiştirmek için yeni dosya Ben (her iki dosya .docx biçimi vardır) kullanın:

Drive.Files.Update update = driveService.files().update(fileIdOfFileToReplace,fileMeta,fileContent); 
     update.set("uploadType", "resumable"); 
     update.getMediaHttpUploader().setDirectUploadEnabled(false); 
     update.getMediaHttpUploader().setChunkSize(MediaHttpUploader.DEFAULT_CHUNK_SIZE); 
     File updatedFile = update.execute(); 

yeni bir dosya yükleme ince wHE işleri Ben InputStreamContent veya AbstractInputStreamContent kullanıyorum. Ama güncelleme her google api maven bağımlılık google-api-istemci dışlanmasını vererek, bunu çözüldü hem

java.lang.IllegalArgumentException 
    at com.google.api.client.repackaged.com.google.common.base.Preconditions.checkArgument(Preconditions.java:111) 
    at com.google.api.client.util.Preconditions.checkArgument(Preconditions.java:37) 
    at com.google.api.client.googleapis.media.MediaHttpUploader.setInitiationRequestMethod(MediaHttpUploader.java:872) 
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.initializeMediaUpload(AbstractGoogleClientRequest.java:237) 
    at com.google.api.services.drive.Drive$Files$Update.<init>(Drive.java:3163) 
    at com.google.api.services.drive.Drive$Files.update(Drive.java:3113) 
    at com.util.DocumentsUtil.updateFile(DocumentsUtil.java:22) 
    at com.controllers.collab.documents.Documents.fileUpload(Documents.java:165) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:44) 
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221) 
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136) 
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110) 

cevap

0

ile "java.lang.IllegalArgumentException" verir. Daha sonra, sonatype repo'dan google-api-client-1.22.0-SNAPSHOT bağımlılığı eklendi. İyi çalışıyor