简体   繁体   中英

File missing in Google Cloud Storage on AppEngine after following instructions

I wrote a file to Google Cloud Storage using the instructions given here:

https://developers.google.com/appengine/docs/java/googlestorage/overview

The code runs and executes successfully, however, after logging into my Storage account, I don't see the newly written file in my bucket.

Any ideas as to why?

So this is the export code:

This is the code I am using:

        try {   
            // Get the file service
            FileService fileService = FileServiceFactory.getFileService();

            /**
             * Set up properties of your new object
             * After finalizing objects, they are accessible
             * through Cloud Storage with the URL:
             * http://storage.googleapis.com/my_bucket/my_object
             */
            GSFileOptionsBuilder optionsBuilder = new GSFileOptionsBuilder()
              .setBucket(bucket)
              .setKey(key)
              .setAcl("public-read");

            // Create your object
            AppEngineFile writableFile = fileService
                    .createNewGSFile(optionsBuilder.build());

            // Open a channel for writing
            boolean lockForWrite = false;
            FileWriteChannel writeChannel = fileService.openWriteChannel(
                    writableFile, lockForWrite);

            // For this example, we write to the object using the
            // PrintWriter
            PrintWriter out = new PrintWriter(Channels.newWriter(
                    writeChannel, "UTF8"));

            Iterator<String> it = spRes.iterator();

            while (it.hasNext()) {
                out.println(it.next());
            }

            // Close without finalizing and save the file path for writing
            // later
            out.close();

            String path = writableFile.getFullPath();

            // Write more to the file in a separate request:
            writableFile = new AppEngineFile(path);

            // Lock the file because we intend to finalize it and
            // no one else should be able to edit it
            lockForWrite = true;
            writeChannel = fileService.openWriteChannel(writableFile,
                    lockForWrite);

            // Now finalize
            writeChannel.closeFinally();
        } catch (IOException e) {
            result = "Failed to export";
            e.printStackTrace();
        }

I believe that you have not added the email of your application which you can find under Application Setting of your appengine application.

Then you need to add this email in the Team under Google API Console for Google Cloud Storage with is Owner privilege. Make sure you are also using the same bucket name which you created in Online Browser Tool for Cloud Storage in the UploadOptions .

Looks like I had 2 different projects setup in the Google Cloud Console. I was updating the wrong project.

Works now.

Thank you for your help.

As Ankur said, you have to deploy your code on appengine to write to Cloud Storage. Otherwise the files will only be stored on your local hard disk.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM