在 App Engine 中调整大图像的大小

发布于 2024-07-25 16:28:28 字数 163 浏览 6 评论 0原文

我在 Google App Engine 上有一个应用程序,可以接受用户上传的图像。 我设想的问题是,用户将直接从相机上传这些图像,并且文件大小通常大于 1MB,这是图像 API(将用于调整图像大小)的限制。

接受上传 1.5MB 图像文件并将其大小调整到 1MB 以下的最佳方法是什么?

I've got an app on Google App Engine that will accept image uploads from users. The problem that I envision is that users will upload these images directly from their cameras, and file sizes are often greater than 1MB, which is the limit for the image API (which would be used to resize the images).

What's the best way to accept the upload of say a 1.5MB image file, and resize it to under 1MB?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

走野 2024-08-01 16:28:28

虽然 App Engine 文档中对此并不清楚,但通过使用 Blobstore 和图像处理服务的组合可以实现这一点。

您必须:

  1. 将图像上传到 Blobstore
  2. 从 Blobstore 检索图像
  3. 对图像执行图像操作,导致大小小于 1mb

我已经写了一篇关于此的文章 -> http://socialappdev.com/uploading-and-re-在 app-engine-11-2010 上调整大图像大小

While this is not clear in the App Engine documentation, this is possible by using a combination of the Blobstore and the Image Manipulation Service.

You must:

  1. Upload the Image into the Blobstore
  2. Retrieve the Image from the Blobstore
  3. Perform the Image Manipulation with an Image resulting in less than 1mb in size

I've written up a post about this -> http://socialappdev.com/uploading-and-re-sizing-large-images-on-app-engine-11-2010.

不再见 2024-08-01 16:28:28

这里有两种(类似的)方法来解决这个问题:

  1. 如果您想自己控制一切,您可以在您的服务器上放置一个调整大小脚本,该脚本获取原始上传图像的 URL(由于大小可能高达 10MB) HTTP 响应大小限制,但您必须将其作为 1MB 块存储在数据存储中),从应用程序下载它,调整其大小,然后POST将其返回到您的应用程序。 当然,所有这些交互都需要某种授权,这样就不会被滥用。 或者,将图像直接POST 到外部服务器,但随后您必须将其他表单数据发送回您的应用程序,或使用单独的表单来上传图像。
  2. 使用外部成像服务。 我会推荐 Picnik。 请参阅他们的 API 文档。 正如您所看到的,它允许您创建一个表单,将图像直接发布到他们的服务器,然后用户可以编辑图像(并调整大小),然后将图像发布回您的服务器。 使用此解决方案,您必须以单独的表单上传图像,因为 Picnik 会收到您的所有 POST 数据。

我推荐第 2 点,因为它不需要您绕过 Google App Engine 限制,并且由于您的用户直接从相机上传图像,他们可能无论如何都想对它们做一些事情(例如裁剪)。

Here are two (similar) ways to solve this:

  1. If you want to keep everything controlled yourself, you can put a resize script on a server of yours, which takes the URL to the raw uploaded image (which can be up to 10MB due to HTTP response size limit, but you would have to store it as 1MB chunks in the datastore), downloads it from your application, resizes it, and then POSTs it back to your application. All this interaction would need some kind of authorization of course, so that it can't be abused. Alternatively, POST the image directly to your external server, but then you have to either send the other form data back to your application, or use a separate form for the image upload.
  2. Use an external imaging service. I would recommend Picnik. See their API documentation. As you can see, it lets you make a form that posts the image directly to their servers, then the user can edit the image (and resize), then the image is posted back to your server. With this solution you have to upload the image in a separate form, since Picnik receives all your POST data.

I recommend point 2, because it doesn't require you to go around Google App Engine limitations and since your users are uploading images straight from the camera, they will probably want to do something with them anyways (such as crop.)

够运 2024-08-01 16:28:28

这是一个难题。 “显而易见”的答案,使用 google.appengine.api.images .resize,不起作用,因为它太大了。 :) 因此,您必须使用第三方软件,无论是在服务器上(由于 App Engine 的限制,这会很棘手)还是在客户端上(例如 Java 上传器)。

That's a conundrum. The "obvious" answer, using google.appengine.api.images.resize, won't work because it's too big. :) So you will have to use third-party software, either on the server (which will be tricky because of App Engine's limitations) or the cilent (e.g. a Java uploader).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文