php - CloudStorageTools::createUploadUrl redirecting to incorrect url on upload -
i have wordpress multi-site install running on gae, works great part.
i want users upload files via front-end custom file handler @ {customdomain.com}/app/client/{client_id}/upload_profile_image/ (i'm using rewrite rules)
this works on non-app-engine setup (apache/php) when using gcs uploader seem redirected main site domain @ url: {maindomain}/wp-signup.php?new=
this code based on code wp google-app-engine plugin:
$url = site_url('/app/client/' . $client->id . '/upload_profile_image/'); require_once 'google/appengine/api/cloud_storage/cloudstoragetools.php'; $options = [ 'gs_bucket_name' => get_option('appengine_uploads_bucket', ''), 'url_expiry_time_seconds' => 60 * 60 * 24, // 1 day maximum ]; $wp_maxupsize = wp_max_upload_size(); // set max_bytes_per_blob option if max upload size positive int if (is_int($wp_maxupsize) && $wp_maxupsize > 0) { $options['max_bytes_per_blob'] = $wp_maxupsize; } // setup internal authentication $sign_result = \google\appengine\api\app_identity\appidentityservice::signforapp(auth_key . get_current_user_id()); $url = add_query_arg('gae_auth_user', get_current_user_id(), $url); $url = add_query_arg('gae_auth_key', $sign_result['key_name'], $url); $url = add_query_arg('gae_auth_signature', urlencode(base64_encode($sign_result['signature'])), $url); $url = \google\appengine\api\cloud_storage\cloudstoragetools::createuploadurl($url,$options);
when submit file (via drag/drop using dropzone) see following requests:
accept:application/json accept-encoding:gzip, deflate accept-language:en-us,en;q=0.8,es;q=0.6 cache-control:no-cache connection:keep-alive content-length:49190 content-type:multipart/form-data; boundary=----webkitformboundarytvowwgs3diihzpnf cookie: {cookies} host:{customdomain} origin:http://{customdomain} pragma:no-cache referer:http://{customdomain}/app/client/27/view/ user-agent:mozilla/5.0 (windows nt 6.3; wow64) applewebkit/537.36 (khtml, gecko) chrome/41.0.2272.89 safari/537.36 x-requested-with:xmlhttprequest
the reply this:
alternate-protocol:80:quic,p=0.5,80:quic,p=0.5 cache-control:no-cache, must-revalidate content-length:0 content-type:text/html date:tue, 17 mar 2015 03:07:53 gmt expires:fri, 01 jan 1990 00:00:00 gmt location:http://{maindomain}/wp-signup.php?new= pragma:no-cache server:uploadserver ("built on mar 6 2015 11:14:41 (1425669281)") x-appengine-estimated-cpm-us-dollars:$0.000009 x-appengine-resource-usage:ms=174 cpu_ms=22
which fails upload , in console: xmlhttprequest cannot load http://{maindomain}/wp-signup.php?new=. no 'access-control-allow-origin' header present on requested resource. origin 'http://{customdomain}' therefore not allowed access. response had http status code 404.
here app.yaml:
application: version: 1 runtime: php55 api_version: 1 default_expiration: "1h" inbound_services: - warmup handlers: - url: /robots.txt static_files: robots.txt upload: robots.txt - url: /favicon.ico static_files: wordpress/favicon.ico upload: wordpress/favicon.ico - url: /(.*\.(htm|html|css|js))$ static_files: wordpress/\1 upload: wordpress/.*\.(htm|html|css|js)$ application_readable: true - url: /wp-content/(.*\.(ico|jpg|png|gif|svg|ttf|eot|woff|swf))$ static_files: wordpress/wp-content/\1 upload: wordpress/wp-content/.*\.(ico|jpg|png|gif|svg|ttf|eot|woff|swf)$ application_readable: true - url: /(.*\.(ico|jpg|png|gif))$ static_files: wordpress/\1 upload: wordpress/.*\.(ico|jpg|png|gif)$ - url: /wp-admin/(.+) script: wordpress/wp-admin/\1 - url: /wp-admin/ script: wordpress/wp-admin/index.php - url: /wp-login.php script: wordpress/wp-login.php - url: /wp-cron.php script: wordpress/wp-cron.php - url: /wp-multi-cron.php script: wordpress/wp-multi-cron.php - url: /xmlrpc.php script: wordpress/xmlrpc.php - url: /wp-(.+).php script: wordpress/wp-\1.php - url: /(.+)?/? script: wordpress/index.php - url: /wp-admin/network/ script: wordpress/wp-admin/network/index.php - url: /wp-admin/network/(.+) script: wordpress/wp-admin/network/\1 - url: /([_0-9a-za-z-]+/)?(wp-(content|admin|includes).*\.(htm.*$|html.*$|css.*$|js.*$|ico.*$|jpg.*$|png.*$|gif.*$|woff.*$|ttf.*$|eot.*$|svg.*$)) static_files: wordpress/\2 upload: wordpress/([_0-9a-za-z-]+/)?(wp-(content|admin|includes).*\.(htm.*$|html.*$|css.*$|js.*$|ico.*$|jpg.*$|png.*$|gif.*$|woff.*$|ttf.*$|eot.*$|svg.*$)) application_readable: true pagespeed: domains_to_rewrite: url_blacklist: enabled_rewriters: - lefttrimurls disabled_rewriters: - combinecss - combinejs - movecsstohead skip_files: - wordpress/wp-content/uploads/.* - ^(.*/)?.*/.svn/.*$
i'm @ loss on issue. regular uploads via wp backend work fine, has i'm doing wrong. appreciated.
i found solution problem, suspected doing wrong.
for brevity omitted if statements caused $url empty before being passed 'createuploadurl' why after upload being redirected default site.
this happens when code late night after long day.
Comments
Post a Comment