0

Error:

incompatible types: java.io.File cannot be converted to com.google.api.services.drive.model.File

I have this error when i want to use the code to upload a file to drive. I am using the drive API in android studio.

File fileMetadata = new File("video.mp4");
java.io.File filePath = new java.io.File(mVideoFileName);
fileMetadata.createNewFile();
FileContent mediaContent = new FileContent("video/mp4", filePath);
Drive driveService = getDriveService(HTTP_TRANSPORT);
File file = driveService.files().create(fileMetadata)
        .setFields("1DpOLhFd4_ZpeQTvROBAmIyfarn80Yg5S")
        .execute();

Why do I get this error?

1
  • 1
    It seems like you used a file of type java.io.File where a type of file com.google.api.services.drive.model.File was expected. Could you provide more of the code, the line numbers and the line numbers mentioned in the stack trace? Commented Feb 3, 2023 at 18:07

1 Answer 1

2

java.io.File is a file in the local file system, while com.google.api.services.drive.model.File is a Google Drive file.

You need to use the com.google.api.services.drive.model.File object to represent the Google Drive file you want to create and upload, instead of the java.io.File object.

Change the code to:

com.google.api.services.drive.model.File fileMetadata = new com.google.api.services.drive.model.File();
fileMetadata.setName("video.mp4");

This should resolve the incompatibility issue.

Sign up to request clarification or add additional context in comments.

Comments

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.