1

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());

https://google-api-client-libraries.appspot.com/documentation/drive/v2/java/latest/com/google/api/services/drive/Drive.Files.Insert.html

2
  • have you read this? Commented Dec 30, 2012 at 7:24
  • Yes. I've been over the documentation with a fine toothed comb. In fact most of the code above is from the example google gives. Commented Dec 30, 2012 at 15:05

1 Answer 1

3

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());
}
Sign up to request clarification or add additional context in comments.

1 Comment

in the insert line what is the service.files() what the service field

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.