我已经知道Google云端存储中没有文件夹(它们被视为对象),所以请查看我的问题并了解我的意思.谢谢 :-)
这是我上传对象的方法,在我的具体情况下,我想上传一个“文件夹”,所以一个以’/’结尾的文件(例如:’newfolder /’),但我收到一个GoogleJson我的代码末尾的execute()中的错误.
[错误]:
Uncaught exception from servlet
com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 OK
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"message" : "Required",
"reason" : "required"
}, {
"domain" : "global",
"message" : "Required",
"reason" : "required"
}, {
"domain" : "global",
"message" : "Required",
"reason" : "required"
} ],
"message" : "Required"
}
[我方法中的代码]:
StorageObject objectMetadata = null;
//default bucket
String bucketRootName = “defaultbucketname”;
//First Folder
String folderAppName = “myfolder”;
//folder that i want to create (upload)
folderName+="/";
String folderPath = folderAppName + "/" + folderName;
if (useCustomMetadata) {
List<ObjectAccessControl> acl = Lists.newArrayList();
acl.add( new ObjectAccessControl().setEntity("allAuthenticatedUsers").setRole("OWNER"));
objectMetadata = new StorageObject()
.setName(folderPath)
.setAcl(acl)
.setContentDisposition("attachment");
}
Storage.Objects.Insert insertObject = storage.objects().insert(bucketRootName, objectMetadata);
StorageObject metadata = insertObject.execute();
return metadata;
为了拥有一个像这样的路径的桶:
defaultbucketname / MyFolder文件/文件夹名/
有谁知道如何解决它?
非常感谢
最佳答案 上载的对象必须具有Content-Type,即使它们的字节大小为零.
另外,我很确定你必须上传一个实际文件,即使它的大小为零字节.