How do I rename a file to google drive rest api? Retrofit2

半城伤御伤魂 提交于 2019-12-13 14:46:14

问题


In the Google documentation about it is not written, I use retrofit 2. Help. Write what request should be sent and what parameters to transmit

interface:

 @PATCH("drive/v3/files/{fileId}")
    @Multipart
    Call<ResponseBody> renameFileGoogle(
            @Path("fileId")String fileId, 
            @Part MultipartBody.Part metaPart
    );

call metod:

public void renameMetod(String id, String title) {
    String content = "{\"name\": \"" + title + "\"}";
  MediaType contentType = MediaType.parse("application/json; charset=UTF-8");
    MultipartBody.Part metaPart = MultipartBody.Part.create(RequestBody.create(contentType, content));
    Call<ResponseBody> renameRequest = server.renameFileGoogle(id, metaPart);
    renameRequest.enqueue(new Callback<ResponseBody>()...

回答1:


It's there in the documentation https://developers.google.com/drive/v2/reference/files/patch

You need to send an HTTP PATCH request

PATCH https://www.googleapis.com/drive/v2/files/{fileId}

RequestBody:
{"title":"newTitle"}

For version 3 https://developers.google.com/drive/v3/reference/files/update

PATCH https://www.googleapis.com/drive/v3/files/{fileId}
RequestBody:
{"name":"newTitle"}


来源:https://stackoverflow.com/questions/43705453/how-do-i-rename-a-file-to-google-drive-rest-api-retrofit2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!