MIME type switched from “image/jpeg” to “image/png”

断了今生、忘了曾经 提交于 2019-12-10 11:53:29

问题


The following 2 code snippets demonstrate the problem I ran into with the NEW Google Drive Android API / Google Play Services 4.2 (libver 15). Or is it a feature I don't know about? All error checking and initialization is removed in order to keep the code simple.

1/ I create a picture of "image/jpeg" MIME type;

GoogleApiClient mGAC;
byte[] jpgBuffer;
DriveFolder fldr;

ContentsResult rslt = Drive.DriveApi.newContents(mGAC).await();
Contents cont = rslt.getContents();
cont.getOutputStream().write(jpgBuffer);
MetadataChangeSet meta = new MetadataChangeSet.Builder()
  .setTitle("foo.jpg").setMimeType("image/jpeg")
  .build();
fldr.createFile(mGAC, meta, cont);

Everything is nice and dandy in the Drive. Image is there, looking great, I can even send it to my mom. But this is not what I'm after. I would like to retrieve it in another part of my Android app.

2/ So I try this:

Query query = new Query.Builder().addFilter(
  Filters.eq(SearchableField.MIME_TYPE, "image/jpeg")
).build();
MetadataBufferResult rslt = Drive.DriveApi.query(mGAC, query).await();
for (Metadata md : rslt.getMetadataBuffer()) {
  Log.d("TAG", md.getTitle() + " " + md.getMimeType());
}

Result: big, fat NOTHING.

I'm not giving up, so the next logical step is to look for ANY file. And the file "foo.jpg" I saved in step 1/ is showing as "image/png" MIME type.


回答1:


Mystery is solved. IT IS A FEATURE! The "jpgBuffer" in

cont.getOutputStream().write(jpgBuffer);

actually contains PNG binary data. So even if my app specified "image/jpeg" MIME type, Google after snooping through my (my user's) data decided to correct MIME type to "image/png". It should also be noted that it happens with some delay, making the debugging process even more mysterious.



来源:https://stackoverflow.com/questions/21868835/mime-type-switched-from-image-jpeg-to-image-png

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