seanpj
seanpj

Reputation: 6755

android modify meta data google drive

all you guys who know things I don't :-)

I've run into this problem that may not be actually a problem, only a revelation that I don't know what I'm doing. AGAIN!

I'm uploading a JPEG with some description and indexable keywords. Works like a charm. But I can't figure out how to add/modify meta data later, without creating another instance of the file. So, when I add a picture of my dog with description "dog", I end up with what I wanted. But if I try to modify the metadata by either using:

      gooFl = drvSvc.files().insert(meta).execute();

or

      gooFl = drvSvc.files().insert(meta,null).execute();

I end up with a new file (of the same name) on GOOGLE Drive. See the code snippet below:

    File meta = new File();
    meta.setTitle("PicOfMyDog.jpg");
    meta.setMimeType("image/jpeg");
    meta.setParents(Arrays.asList(new ParentReference().setId(ymID)));
    File gooFl = null;
    if (bNewJPG == true) {
      meta.setDescription("dog");
      meta.setIndexableText(new IndexableText().setText("dog"));
      gooFl = drvSvc.files().insert(meta, 
       new FileContent("image/jpeg", new java.io.File(fullPath("PicOfMyDog.jpg"))))
       .execute();
    } else {
      meta.setDescription("dick");
      meta.setIndexableText(new IndexableText().setText("dick"));
      // gooFl = drvSvc.files().insert(meta).execute();
      gooFl = drvSvc.files().insert(meta,null).execute();
    }
    if (gooFl != null)
      Log.d("atn", "success  " + gooFl.getTitle()); 

It is the "else" branch I'm asking about. First file one has meatadata "dog", second "dick". So, what's the solution. Do I delete the previous instance (and how)? Is there another syntax / method I don't know about? thank you, sean

Upvotes: 1

Views: 224

Answers (2)

Burcu Dogan
Burcu Dogan

Reputation: 9213

If you need to modify the metadata, use files.patch.

drvSvc.files().patch(id, meta).execute();

In cases you need both modify the metadata and the file contents, use files.update.

drvSvc.files().update(id, meta, content).execute();

Insertions make POST requests that always create a new resource.

Upvotes: 2

ianhanniballake
ianhanniballake

Reputation: 200030

You need to use Files.Patch if you want to update only Metadata. files().insert always creates a new file.

A full list of File commands and what operations you need to use can be found in the API Reference

Upvotes: 0

Related Questions