Reputation: 161
I am uploading a file to google drive successfully, however, am having difficulty setting the convert flag.
Below is what I tried, based on the reference documents I found.
Can anyone suggest what I might be doing wrong?
java.io.File fileContent = new java.io.File(csvfilepath);
FileContent mediaContent = new FileContent("text/csv", fileContent);
// File's metadata.
File body = new File();
body.setTitle(fileContent.getName());
body.setMimeType("text/csv");
File file = service.files().insert(body, mediaContent);//.execute();
file.setConvert(true);
file.execute();
if (file != null) {
showToast("Data Uploaded: " + file.getTitle());
Upvotes: 1
Views: 1806
Reputation: 15024
You are trying to set the convert flag to the wrong object, try replacing your code with the following:
java.io.File fileContent = new java.io.File(csvfilepath);
FileContent mediaContent = new FileContent("text/csv", fileContent);
// File's metadata.
File body = new File();
body.setTitle(fileContent.getName());
body.setMimeType("text/csv");
// THIS IS THE NEW CODE
Insert request = service.files().insert(body, mediaContent);
request.setConvert(true);
File file = request.execute();
// END OF NEW CODE
if (file != null) {
showToast("Data Uploaded: " + file.getTitle());
}
Upvotes: 3