如何在Google云端存储中使用西里尔文件名?

时间:2015-07-09 14:00:41

标签: google-app-engine google-cloud-storage

我上传了用户文件并将其保存到Google云端存储:

$params

适用于拉丁名字。但是如果用户上传带有西里尔字符的文件,我会收到以下错误:

namespace app\controllers\actions;

use Yii;
use yii\base\Model;
use yii\db\ActiveRecord;
use yii\web\ServerErrorHttpException;
use yii\rest\Action;
use app\models\YourSubModel;

class WhateverAction extends Action
{

    public $scenario = Model::SCENARIO_DEFAULT;
    public $params;

    public function run($id)
    {
        $model = $this->findModel($id);

        if ($this->checkAccess) {
            call_user_func($this->checkAccess, $this->id, $model);
        }

        $model->scenario = $this->scenario;
        $model->load($this->params, '');

        foreach ($this->params["subModels"] as $subModel) {
          /**
            * your code related to each of your model's posted child
            * for example those lines will relate each child model
            * to the parent model by saving that to database as their
            * relationship has been defined in their respective models (many_to_many or one_to_many)
            *
            **/
            $subModel = YourSubModel::findOne($subModel['id']);
            if (!$subModel) throw new ServerErrorHttpException('Failed to update due to unknown related objects.');
            $subModel->link('myParentModelName', $model);
            //...
        }

        // ...

        return $model;
    }
}

我该如何解决这个问题?

UPD。我已尝试将class MyHandler(webapp2.RequestHandler): def post(self): my_file = self.request.POST['agreement'] default_bucket = app_identity.get_default_gcs_bucket_name() gcs_filename = '/%s/%s' % (default_bucket, my_file.filename) with gcs.open(gcs_filename, 'w', content_type=my_file.type) as f: f.write(my_file.value) 应用于u'\u0410' Traceback (most recent call last): File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1511, in __call__ rv = self.handle_exception(request, response, e) File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1505, in __call__ rv = self.router.dispatch(request, response) File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1253, in default_dispatcher return route.handler_adapter(request, response) File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1077, in __call__ return handler.dispatch() File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 547, in dispatch return self.handle_exception(e, self.app.debug) File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 545, in dispatch return method(*args, **kwargs) File "/base/data/home/apps/s~myappid/1.385593846880232980/myapp.py", line 307, in post with gcs.open(gcs_filename, 'w', content_type=my_file.type) as f: File "libs/cloudstorage/cloudstorage_api.py", line 91, in open filename = api_utils._quote_filename(filename) File "libs/cloudstorage/api_utils.py", line 94, in _quote_filename return urllib.quote(filename) File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/urllib.py", line 1263, in quote return ''.join(map(quoter, s)) KeyError: u'\u0410' ,它几​​乎正常,但GCS文件存储了不可读的名称,如urllib.quote()

0 个答案:

没有答案