转换标志TRUE插入操作失败 [英] Insert operation with convert flag TRUE fails

查看:103
本文介绍了转换标志TRUE插入操作失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用xdocreport生成WORD文件的报告。



在生成的报告中,我使用MIME-TYPE application / application创建了 InputStreamContent vnd.openxmlformats-officedocument.wordprocessingml.document(MS WORD - DOCX)写入Google Drive:

  //使用xdocreport创建Word文件流
OutputStream2InputStream outputStream = new OutputStream2InputStream(); // buffer
report.process(context,outputStream);
//为Google Drive创建输入流
InputStreamContent inputStream = new InputStreamContent(application / vnd.openxmlformats-officedocument.wordprocessingml.document,
outputStream.getInputStream());
inputStream.setLength(outputStream.size());

写入MSWORD DOCUMENT WORKS FINE(CONVERT = FALSE):

  File file = new File(); 
插入insertOperation = service.files()。insert(file,inputStream).setConvert(false);
file.setTitle(test.docx);
file.setMimeType(inputstream.getType());
文件结果= insertOperation.execute();

导致在我的Google云端硬盘中创建WORD DOCX文件。



使用CONVERT = TRUE FAILS写入输入流

  File file = new File (); 
插入insertOperation = service.files()。insert(file,inputStream).setConvert(true);
file.setTitle(test);
//file.setMimeType(inputstream.getType()); //这里有什么?
文件结果= insertOperation.execute();

结果

1。当不设置MIME类型时:新创建的文件 result 具有 0字节 MIME类型:application / vnd。 google-apps.kix



2。当设置MIME类型: MIME-TYPE设置为application / vnd.google-apps.document并且convert = true时,结果为400:BAD REQUEST。



我做错了什么?

解决方案

这是一个常见问题。请勿在请求元数据中设置MIME类型。 Google云端硬盘将决定要转换为的MIME类型。



您的行标记为 //此处?应该保留出去。


I am generating reports resulting in WORD files using xdocreport.

From the generated report, I create a InputStreamContent with MIME-TYPE "application/vnd.openxmlformats-officedocument.wordprocessingml.document" (MS WORD - DOCX) to write to Google Drive :

// create Word file stream using xdocreport
OutputStream2InputStream outputStream = new OutputStream2InputStream(); // buffer
report.process(context, outputStream);
// create inputstream for Google Drive
InputStreamContent inputStream = new InputStreamContent("application/vnd.openxmlformats-officedocument.wordprocessingml.document",
        outputStream.getInputStream());
inputStream.setLength(outputStream.size());

WRITING MSWORD DOCUMENT WORKS FINE (CONVERT= FALSE) :

File file = new File();
Insert insertOperation = service.files().insert(file, inputStream).setConvert(false);
file.setTitle("test.docx");
file.setMimeType(inputstream.getType());
File result = insertOperation.execute();

Resulting in a WORD DOCX file created on my Google Drive.

WRITING SAME INPUTSTREAM WITH CONVERT=TRUE FAILS

File file = new File();
Insert insertOperation = service.files().insert(file, inputStream).setConvert(true);
file.setTitle("test");
//file.setMimeType(inputstream.getType()); // what here ? 
File result = insertOperation.execute();

RESULT

1. When NOT setting the mime type : newly created File result has 0 bytes and MIME-type: application/vnd.google-apps.kix

2. When setting the mime type : MIME-TYPE set to "application/vnd.google-apps.document" and convert = true, results in 400: BAD REQUEST.

What am I doing wrong ?

解决方案

This is a common problem. Don't set a MIME type in the request metadata. Google Drive will decide the MIME type to convert to.

Your line marked // what here ? should be left out.

这篇关于转换标志TRUE插入操作失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆