1
我試圖將文件插入我的Google雲端硬盤。將文件插入Google雲端硬盤 - MIME類型不正確
我用這個方法,我發現在這裏:Files: insert
這裏的招牌:
/**
* Insert new file.
*
* @param service Drive API service instance.
* @param title Title of the file to insert, including the extension.
* @param description Description of the file to insert.
* @param parentId Optional parent folder's ID.
* @param mimeType MIME type of the file to insert.
* @param filename Filename of the file to insert.
* @return Inserted file metadata if successful, {@code null} otherwise.
*/
private static File insertFile(Drive service, String title, String description,
String parentId, String mimeType, String filename);
這是我做進入主:
public static void main(String[] args) throws IOException {
// Build a new authorized API client service.
Drive service = getDriveService();
java.io.File fi = new java.io.File("/home/davide/Scrivania/test.txt");
if (!fi.exists()) {
fi.createNewFile();
}
insertFile(service, "test.txt", "JSON string of HashMap",
"/", "txt", "/home/davide/Scrivania/test.txt");
我不知道如果我設置了正確的parentId,則文檔會告知它是可選的。
但發現錯誤是:
An error occured: com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"message" : "Media type 'txt' is not supported. Valid media types: [*/*]",
"reason" : "badContent"
} ],
"message" : "Media type 'txt' is not supported. Valid media types: [*/*]"
}
UPDATE
隨着純文本/ MIME類型,錯誤是:
An error occured: com.google.api.client.googleapis.json.GoogleJsonResponseException: 404 Not Found
{
"code" : 404,
"errors" : [ {
"domain" : "global",
"location" : "file",
"locationType" : "other",
"message" : "File not found: /",
"reason" : "notFound"
} ],
"message" : "File not found: /"
}
'txt'不是有效的[媒體類型](http://www.iana.org/assignments/media-types/media-types.xhtml)(MIME類型)。您可能希望將'text/plain'用於'mimeType'參數。 –
@PhilRoss,我試了一下。不能再次工作,請參閱上面的更新。 – Dave
請整理您的問題並將解決方案作爲答案發布。否則它可能會被西班牙宗教裁判所降低。 – pinoyyid