Reputation: 3
Based on Google Drive API reference guiding how to insert file Files.insert
// File's metadata.
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);
try {
File file = service.files().insert(body, mediaContent).execute();
// Uncomment the following line to print the File ID.
// System.out.println("File ID: " + file.getId());
return file;
} catch (IOException e) {
System.out.println("An error occured: " + e);
return null;
}
However, my application is web application and it does not support java.io.File package when uploaded to Google app engine => I can not use this to set content for file object
java.io.File fileContent = new java.io.File(filename);
FileContent mediaContent = new FileContent(mimeType, fileContent);
Is there any other methods to implement this such as using blob or binary data to be file content instead?
Upvotes: 0
Views: 714
Reputation: 22306
Instead of FileContent
, use one of the other subclasses of AbstractInputStreamContent
such as ByteArrayContent
Upvotes: 1