Tengo blobs almacenados en mi almacén de blob y quiero enviar estos archivos a Google Drive. Cuando utilizo el URLFetchService Google App EngineCómo PUBLICAR un archivo grande (> 5 mb) de Blobstore a Google Drive?
URLFetchService fetcher = URLFetchServiceFactory.getURLFetchService();
URL url = new URL("https://www.googleapis.com/upload/drive/v1/files");
HTTPRequest httpRequest = new HTTPRequest(url, HTTPMethod.POST);
httpRequest.addHeader(new HTTPHeader("Content-Type", contentType));
httpRequest.addHeader(new HTTPHeader("Authorization", "OAuth " + accessToken));
httpRequest.setPayload(buffer.array());
Future<HTTPResponse> future = fetcher.fetchAsync(httpRequest);
try {
HTTPResponse response = (HTTPResponse) future.get();
} catch (Exception e) {
log.warning(e.getMessage());
}
Problema: Cuando el archivo es superior a 5 mb, que supera el límite del tamaño de la petición URLFetchService (Enlace: https://developers.google.com/appengine/docs/java/urlfetch/overview#Quotas_and_Limits)
Alternativa: Uso la API de Google Drive tengo este código:
File body = new File();
body.setTitle(title);
body.setDescription(description);
body.setMimeType(mimeType);
// File's content.
java.io.File fileContent = new java.io.File(filename);
FileContent mediaContent = new FileContent(mimeType, fileContent);
File file = service.files().insert(body, mediaContent).execute();
problema con esta solución: FileOutputStream no es compatible con Google App Engine para administrar byte [] leer desde Blobstore.
¿Alguna idea?
Gracias para adaptar mi código Drive. Actualizo mi aplicación aprovechando la carga reanudable. Después de cargar el código de Google App Engine consigo java.lang.NoSuchMethodError: $ com.google.api.services.drive.Drive archivos $ Insert.getMediaHttpUploader() FCM/google/api/cliente/googleapis/MediaHttpUploader; Necesito investigar un poco más sobre esto ... – Martin
¿Qué versión de google-api-java-client tienes? ¿Es el último? Ver aquí: http://code.google.com/p/google-api-java-client/ –
Gracias Vic! ¡Después de actualizar todas las bibliotecas API usadas, su código proporcionado funciona perfectamente bien! – Martin