Domanda

So già che non ci sono cartelle all'interno di una stoccaggio di Google Cloud (sono trattati come oggetti), quindi per favore dai un'occhiata alla mia domanda e puoi capire cosa intendo.Grazie: -)

Questo è il mio metodo per caricare un oggetto e nel mio caso specifico, vorrei caricare una "cartella", quindi un file che termina con un '/' (ad esempio: 'newfolder /'), ma ioRicevi un errore Googlejson nell'esegui () alla fine del mio codice.

[ERRORE]:

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"
}
.

[Il mio codice all'interno del metodo]:

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;
.

Per avere un secchio con un percorso come questo: DefaultBucketName / MyFolder / Carryname /

Qualcuno sa come risolverlo?

Grazie mille

È stato utile?

Soluzione

Oggetti caricati Must Avere un tipo di contenuto, anche se sono zero byte grandi.

Inoltre, sono abbastanza sicuro che è necessario caricare un file effettivo, anche se è di dimensioni zero byte.

Altri suggerimenti

Non penso che tu possa creare una cartella in questo modo.Ma puoi crearlo durante il caricamento del file impostando il nome.

E.G.Se si desidera creare un file in Piega / Foldb / Test.txt, è possibile farlo a seguito del modo.

            InputStream is = Files.newInputStream(path); //path if java.nio.file.Path
            String mimeType = Files.probeContentType(path);
            InputStreamContent isContent = new InputStreamContent(mimeType, is);
            StorageObject objectMetadata = new StorageObject();
.

storage.objects.insert inserirebject= storage.objects (). inserto (bucketrootname, oggettipatadata, iscontent);

            insertObject.setName("foldA/foldB/"+path.getFileName().toString()); // path.getFileName().toString() will give u test.txt
            insertObject.execute();
.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top