问题
I am new to both Google Cloud Storage and Google Analytics API v4.
I have created a helloworld application where I add JS and CSS files. I have uploaded the same in the google storage. But JS and CSS files are not working.
This is what I have done so far.
- I have created a new project.
- I have generate a new service and keep the downloaded JSON file in the root of the project.
- I have created a storage bucket.
- I am using default app engine.
I am using GCConsole to upload the project. While uploading I am using old settings with new properties. At the end when I give command gcloud app console, in the service list, I do not found and I do not asked by the console to mention the storage bucket. I have add the bucket in my PHP file. Below I have shared my files.
Questions
- I have created storage bucket, service JSON file. I am using default app engine. Is there anything I am missing?
- Is it possible to upload the project in VM Instance and test?
- What is the difference between VM Instance and App Engine?
- How do I create and test proper app.yaml file?
- Is it mandatory to use and configure bucket in PHP code? Is there any alternatives?
- I do not found the project under the bucket I have created. I found it in App Engine > Source. In the bucket there are 3 different folders are created automatically. Is this approach correct?
- Is it possible to update the project URL with user friendly URL?
- How can I run Google Reports API v4 scripts (PHP, Java) in Google Storage?
- Why JS and CSS files are not working?
Project's Folder Structure
\root\
\vendor\
\css\style.css
\js\main.js
index.php
app.yaml
abcde-9c0e6b4e4b6c.json
composer.json
composer.lock
README.md
index.php
<?php
require 'vendor/autoload.php';
use Google\Cloud\Storage\StorageClient;
use google\appengine\api\cloud_storage\CloudStorageTools;
$projectId = 'projid';
$bucketId = 'buckid';
$storage = new StorageClient([
'projectId' => $projectId,
'keyFilePath' => 'abcde-9c0e6b4e4b6c.json',
]);
$gcsBucket = $storage->bucket($bucketId);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<link rel="stylesheet" href="css/style.css">
<title>GCP PHP</title>
</head>
<body>
<h1>Welcome to GCP World</h1>
<div class="p1">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perferendis nihil molestias mollitia iste aliquam placeat quis nobis nesciunt, pariatur ipsa eligendi eveniet ipsam voluptatibus, voluptate eaque alias velit voluptatem id enim sed quisquam praesentium necessitatibus sint. Distinctio nam deleniti, a, eos reprehenderit eligendi, officiis nisi adipisci nostrum et delectus earum.</div>
<div class="p2">Iure, rerum, inventore! Nulla nesciunt autem, facere eius quas, a ipsum necessitatibus adipisci, reprehenderit eaque fugit debitis dicta voluptates dignissimos quos? Tenetur deleniti impedit excepturi dolorem voluptas, quidem animi ullam! Deserunt eum, modi, eligendi et quam, magni sapiente dolorem porro eaque quibusdam nihil ratione consequuntur amet autem voluptas suscipit, molestiae!</div>
<div class="p3">Molestias architecto a expedita nostrum, ullam sapiente quia temporibus nesciunt aperiam, asperiores dolor tempore, delectus ipsam sunt? Consequuntur facere reprehenderit nemo voluptatibus ad facilis nostrum temporibus perferendis sequi quasi voluptas, voluptatum repellendus rerum quas repudiandae quidem ipsam eligendi ex numquam sint culpa itaque eum? A saepe deserunt ea asperiores fugiat.</div>
<div class="footer1"></div>
<script src="js/main.js"></script>
</body>
</html>
app.yaml
runtime: php73
handlers:
- url: /.*
script: auto
runtime_config:
document_root: .
回答1:
You can refer to the documentation for useful information that might solve your questions.
- Creating config files for creating JSON config files.
- You can upload your project into a bucket and create a VM instance and download it from there. But you will have to create the environment for deploying it.
- App Engine is a Platform-as-a-Service, so basically you just do code there and the platform is the one that will manage the rest. Compute Engine is a Infrastructure-as-a-Service. You get your VM instance and you are the one that will manage it, as you own computer. However, check this link to another StackOverflow thread where you can have a further explanation about this.
- For creating a proper app.yaml file according to yaml syntax, you can go to this page http://www.yamllint.com/. To create a proper one in Google Cloud Platform for deploying your application, you can have the information about the elements in the documentation about app.yaml Configuration File.
- You can manage your buckets in many different ways, check them out in this documentation for Uploading objects.
- In order to answer that question I would need to know how you created the bucket.
- Yes, it is. With a custom domain you can change the URL.
- There is no way to run anything from Storage if you meant that.
- You are missing the handlers, for using Style Sheets should be like this:
handlers:
# Serve a directory as a static resource.
- url: /stylesheets
static_dir: stylesheets
来源:https://stackoverflow.com/questions/59764735/google-reports-api-v4-to-be-uploaded-google-cloud-storage