Google Cloud Storage - Knowing who uploaded

user2213590

I'm currently porting a webservice I've built to work with Google App Engine. One of the main functions in the webservice is to upload an image (a profile picture, for example). Currently what I do is:

  • Authenticate the user who wants to upload the image using his unique API KEY and other data.
  • Upload the file, give it a unique name and store the name of the file inside the user's row in the mysql database.

Now in order to port the file upload to App Engine I'm using Google Cloud Storage and following this tutorial: https://cloud.google.com/appengine/docs/php/googlestorage/user_upload

I'm trying to get the file upload to work with my Android app the following way:

  • The user makes a request, the webservice authenticates him and sends in response the upload url created by CloudStorageTools::createUploadUrl.
  • The user uploads the image to this URL
  • Now heres the problem: After the upload is done, a POST is made to the given php file in createUploadUrl (I quote from google's docs) with the uploaded file. But how can this script know who uploaded the file it got? I can't pass any parameters indicating who uploaded the file to createUploadUrl so I can't insert the file name to a user in the Cloud SQL database, so now theres only a file not associated with anything in Cloud Storage.

Any hints? Am I missing something?

akgill

I'm posting this as a separate answer because a) it's different approach than the first answer, and b) I'd advocate for my other answer over this one because I think it's best to let GAE handle auth. However, I think you can do what you're trying to do this way:

Instead of routing a singular URL to your upload handler, use a regex match like this in your app.yaml to route any matching URLs to your handler:

 handlers:
 - url: upload_handler/(.*)
   script: my-php-script-that-uploads-stuff.php

Then when invoking createUploadURL, simply pass in your API_KEY after the 'upload_handler/' as a query argument, e.g.

$upload_url = CloudStorageTools::createUploadUrl(sprintf('/upload_handler/?API_KEY=%s', $API_KEY), $options);

Then in my-php-script-that-uploads-stuff.php:

parse_str(parse_url($_SERVER['REQUEST_URI'])['query'])

This will parse the request URL to get the query string and then parse the query string, populating the value of API_KEY with the value passed in the URL in your local scope.

I just tested this pattern of extracting stuff from the request URL in a php script in with dev_appserver and it worked.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

How to set the Content-Type for a file being uploaded to Google Cloud Storage using node.js

Is move_uploaded_file necessary for local storage prior to cloud storage?

Google Appengine Cloud Storage

PHP Google Cloud Storage

Google Cloud Storage Client

Google Cloud Storage

Google Cloud Storage ::制限

Load big file from Google Cloud Storage into Google Cloud Functions?

在 Google Cloud Build 中使用 Google Cloud Storage

Google Cloud Storage returning wrong identity

What is the Google Cloud Storage public read uri?

Google Cloud Storage認証の使用

Generating getServingUrl() in google cloud storage with NodeJs sdk

Snowflake Connection to Google Cloud Storage in Australia

Is it possible to upload files directly to the Google Cloud Storage?

How to initialize Google Cloud Storage with credentials

Moving Google Cloud Storage bucket to another project

gsutil zip directory on google cloud storage

Concat Avro files in Google Cloud Storage

Delete a file inside a folder in Google cloud storage

Google Cloud Storage Notification with Pub/Sub and docs

Accessing files from Google cloud storage in RStudio

Google Cloud Storage WebUIの制限

Google Takeout from G Suite Download from Google Cloud Storage

Google BigQuery, How to load data from google cloud storage to BigQuery

Google Cloud Storage、Compute Engine、InsufficientPermissionエラー

Struggling to read csv files from Google Cloud Storage bucket

Copy from Google Cloud Storage Bucket to S3 Bucket

Upload youtube-dl transcript into Google Cloud storage

TOP 一覧

  1. 1

    Unity:未知のスクリプトをGameObject(カスタムエディター)に動的にアタッチする方法

  2. 2

    セレンのモデルダイアログからテキストを抽出するにはどうすればよいですか?

  3. 3

    Ansibleで複数行のシェルスクリプトを実行する方法

  4. 4

    tkinterウィンドウを閉じてもPythonプログラムが終了しない

  5. 5

    Crashlytics:コンパイラー生成とはどういう意味ですか?

  6. 6

    GoDaddyでのCKEditorとKCfinderの画像プレビュー

  7. 7

    Windows 10 Pro 1709を1803、1809、または1903に更新しますか?

  8. 8

    Chromeウェブアプリのウェブビューの高さの問題

  9. 9

    モーダルダイアログを自動的に閉じる-サーバーコードが完了したら、Googleスプレッドシートのダイアログを閉じます

  10. 10

    Windows 10の起動時間:以前は20秒でしたが、現在は6〜8倍になっています

  11. 11

    Reactでclsxを使用する方法

  12. 12

    ファイル内の2つのマーカー間のテキストを、別のファイルのテキストのセクションに置き換えるにはどうすればよいですか?

  13. 13

    MLでのデータ前処理の背後にある直感

  14. 14

    グラフからテーブルに条件付き書式を適用するにはどうすればよいですか?

  15. 15

    Pythonを使用して同じ列の同じ値の間の時差を取得する方法

  16. 16

    mutate_allとifelseを組み合わせるにはどうすればよいですか

  17. 17

    ネットワークグラフで、ネットワークコンポーネントにカーソルを合わせたときに、それらを強調表示するにはどうすればよいですか?

  18. 18

    テキストフィールドの値に基づいて UIslider を移動します

  19. 19

    BLOBストレージからデータを読み取り、Azure関数アプリを使用してデータにアクセスする方法

  20. 20

    PowerShellの分割ファイルへのヘッダーの追加

  21. 21

    ソートされた検索、ターゲット値未満の数をカウント

ホットタグ

アーカイブ