Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 6.7k
Added blobstore image example#291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| # Copyright 2015 Google Inc. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| """ | ||
| Sample application that demonstrates how to use the App Engine Images API. | ||
| For more information, see README.md. | ||
| """ | ||
| # [START all] | ||
| # [START thumbnailer] | ||
| from google.appengine.api import images | ||
| from google.appengine.ext import blobstore | ||
| import webapp2 | ||
| class Thumbnailer(webapp2.RequestHandler): | ||
| def get(self): | ||
| blob_key = self.request.get("blob_key") | ||
| if blob_key: | ||
| blob_info = blobstore.get(blob_key) | ||
| if blob_info: | ||
| img = images.Image(blob_key=blob_key) | ||
| img.resize(width=80, height=100) | ||
| img.im_feeling_lucky() | ||
| thumbnail = img.execute_transforms(output_encoding=images.JPEG) | ||
| self.response.headers['Content-Type'] = 'image/jpeg' | ||
| self.response.out.write(thumbnail) | ||
| return | ||
| # Either "blob_key" wasn't provided, or there was no value with that ID | ||
| # in the Blobstore. | ||
| self.error(404) | ||
| # [END thumbnailer] | ||
| app = webapp2.WSGIApplication([('/img', Thumbnailer)], debug=True) | ||
| # [END all] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| # Copyright 2015 Google Inc. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| import blobstore | ||
| import mock | ||
| import pytest | ||
| import webtest | ||
| @pytest.fixture | ||
| def app(testbed): | ||
| return webtest.TestApp(blobstore.app) | ||
| def test_img(app): | ||
| with mock.patch('blobstore.images') as mock_images: | ||
| with mock.patch('blobstore.blobstore') as mock_blobstore: | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we make these decorators? less nesting so a little cleaner imo ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can do this after closing the bug | ||
| mock_blobstore.get.return_value = b'123' | ||
| mock_images.resize.return_value = 'asdf' | ||
| mock_images.im_feeling_lucky.return_value = 'gsdf' | ||
| response = app.get('/img?blob_key=123') | ||
| assert response.status_int == 200 | ||
| def test_img_missing(app): | ||
| # Bogus blob_key, should get error | ||
| app.get('/img?blob_key=123', status=404) | ||
| def test_no_img_id(app): | ||
| # No blob_key, should get error | ||
| app.get('/img', status=404) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blobstore should be above images, lint will fail otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint passes for me?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I'm dumb and mis-read ext and api. This is fine.