1
votes

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();
        }
3
Consider adding your actual code, how you executed the code, and how you configure the access control between GCS and App Engine. - Takashi Matsuo
Well on local enviornment this will be stored under _BlobInfo_ entity. - Ankur Jain

3 Answers

3
votes

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.

1
votes

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.

0
votes

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.