I'm using this code
to upload an image from my android app to the user's google drive account.
But how can I modify the code to upload the image to folder named "myFolder"?
meaning to that folder is exist and if not - create such folder and then upload the image there.
What you need to do in order to upload a file to a specific folder is to add the folder's id to the file parents (ref Docs for
file.insert
).So the full things you need to do are:
Code
Find the Folder
Here you can opt for 2 ways: loop all the folders or search for it.
Faster and less resource heavy is to search the folder by name; to do so it's simple:
More info about the possible search parameters.
Create the insert request is as in the sample
before executing it we need to set the parent file.setParents(Arrays.asList(new ParentReference().setId(folder.getFolderId())));
In the end execute the request file.execute();
I haven't tested the code so there might be some typo here and there.