So im trying to upload a text file to my google drive from an android app I am creating. I learned how to upload a picture from the Google tutorial. Also, I will be using the strings from my app in the text file. Potentially, I want to make it a spreadsheet. Any help?
2 Answers
Read Quick Start on Google Android site.
When you are done with all the authentication process, go for How to upload file to Google Drive.
Edit
Reference Links

- 1
- 1

- 25,864
- 13
- 83
- 93
-
I tried reading the "How to upload file to Google Drive" but don't quite get it. It is a little confusing. I am new to Java and Android app. – j_vega19 Mar 28 '13 at 08:28
-
which problem you are facing? Have you run that sample? – Chintan Rathod Mar 28 '13 at 08:46
-
1Problem is that I don't know of I should write a new class? or add the code to my main activity. Furthermore, can I just write in "https:" in java? – j_vega19 Mar 28 '13 at 17:09
-
There are classes available to send HTTP request. Read http://www.vogella.com/articles/AndroidNetworking/article.html. – Chintan Rathod Mar 29 '13 at 05:54
-
refer this link https://stackoverflow.com/a/49297056/1201441, there describe upload file in google drive. you can upload any type of file just change file_path and respected Mime type.. – TejaDroid Mar 15 '18 at 10:55
I spent so much time for that... In my opinion documentation is ..... not so great.
This is how it should be done with REST API v3. MULTIPART UPLOAD example
1. STEP ONE - Create JSON with METADATA
For example:
data class RetrofitMetadataPart(
val parents: List<String>, //directories
val name: String //file name
)
and now create a JSON (I used moshi for this)
val jsonAdapter = moshi.adapter<RetrofitMetadataPart>(RetrofitMetadataPart::class.java)
val metadataJSON = jsonAdapter.toJson(
RetrofitMetadataPart(
parents = listOf("yourFolderId"),
name = localFile.name
)
)
of course you can create this metadata with different parameters,values, and of course in your preferred way. Full list of metadata parameters you have here: https://developers.google.com/drive/api/v3/reference/files/create
2. STEP TWO - Create Multipart with METADATA
We create first part of our request with proper Header
val metadataPart = MultipartBody.Part.create(
RequestBody.create(MediaType.parse("application/json; charset=utf-8"), metadataJSON)
)
3. STEP THREE - Create Multipart with your FILE
Create second part of our request with file
val multimediaPart = MultipartBody.Part.create(
RequestBody.create(MediaType.parse("image/jpeg"), localFile)
)
4. STEP FOUR - call request
googleDriveApi.uploadFileMultipart(
metadataPart,
multimediaPart
)
and this invoke
@Multipart
@POST("upload/drive/v3/files?uploadType=multipart")
fun uploadFileMultipart(
@Part metadata: MultipartBody.Part,
@Part fileMedia: MultipartBody.Part
): Completable
by sending this two Multiparts you get automatically those --foo_bar_baz marks from documentation
"Identify each part with a boundary string, preceded by two hyphens. In addition, add two hyphens after the final boundary string."