通过网页形式将图像上传到 google 云存储 python,google 应用引擎,angularjs
Upload image to google cloud store through a web page form python, google app engine, angularjs
先说,
我想我已经阅读了所有似乎与该主题相关的堆栈交换post。*
我想做什么:
- 我正在尝试允许某些用户通过我网站上的表单将图像发送到 google 云存储..
- 将图像发送到云存储的另一个要求是,我需要在数据存储中创建该图像的模型及其相关属性。
我不确定解决此问题的最佳方法是什么,因为..
我读过的方法:
有很多方法可以将图像获取到云存储:
- 通过 blobstore api
- 通过 python 客户端进行云存储:https://cloud.google.com/appengine/docs/python/googlecloudstorageclient/#Python_About_the_client_library
- 通过休息api(我正在考虑json方法)https://cloud.google.com/storage/docs/json_api/v1/how-tos/upload#simple
我读了很多相互矛盾的信息,
而且我读了很多书,我无法直截了当,
然而,
我认为分辨率是:
对于 blobstore:
- blobstore.uploadtocloudstoragethingmethod 可能有也可能没有文件上传限制大小(不,那不是实际的调用或方法名称)2. blobstore 方法听起来像是要被淘汰了??
杰森API:
“但是,客户端库包括 App Engine 优化,因此使用 REST API 可能需要额外的开发时间。注意:App Engine 开发服务器支持云存储客户端。它不支持 REST API。
对于客户端库:
我不知道。到目前为止看起来还不错。这是我正在考虑使用的方法:
"cloudstorage.open(filename, mode='r', content_type=None,
options=None,
read_buffer_size=storage_api.ReadBuffer.DEFAULT_BUFFER_SIZE,
retry_params=None)
In read mode (r) opens the specified Cloud Storage
object for read. In write mode w, if the specified file exists, it
opens it for an overwrite (append is not supported). If the file
doesn't exist, it is created in the specified bucket."
我用的东西:
- Google 应用引擎
- Python(对于处理程序、模型等)
- angularjs 和 jquery(前端)
- json 有时(后端)
- GAE 样板文件(不要问)
我想我会做什么:
- 获取用户图片:
所以,我找到了这个我测试过的表格。它确实从您的计算机中抓取了一个文件:
<form action="<?php echo $upload_url?>" enctype="multipart/form-data"
method="post">
Files to upload: <br> <input type="file" name="uploaded_files" size="40"> <input type="submit" value="Send">
(不,我不能在操作中使用 php 垃圾。我从文档中的某个地方获取它,但我测试了它,它确实抓取了一个文件,不,它赢了'发送,期望它发送是愚蠢的)
- 修改我当前的处理程序(负责在数据存储中创建图像模型)以也使用
此方法:
"cloudstorage.open(filename, mode='r', content_type=None,
options=None,
read_buffer_size=storage_api.ReadBuffer.DEFAULT_BUFFER_SIZE,
retry_params=None)
In read mode (r) opens the specified Cloud Storage
object for read. In write mode w, if the specified file exists, it
opens it for an overwrite (append is not supported). If the file
doesn't exist, it is created in the specified bucket."
我目前遇到的问题
我不知道那个表单是如何工作的,我不知道如何从这个表单中获取正确的信息给处理程序,也不知道处理程序需要什么信息,所以我可以处理它,创建模型(我已经知道如何在数据存储中创建模型,已经这样做了),并且还使用此方法将图像发送到 google 云存储:
"cloudstorage.open(filename, mode='r', content_type=None,
options=None,
read_buffer_size=storage_api.ReadBuffer.DEFAULT_BUFFER_SIZE,
retry_params=None)
In read mode (r) opens the specified Cloud Storage
object for read. In write mode w, if the specified file exists, it
opens it for an overwrite (append is not supported). If the file
doesn't exist, it is created in the specified bucket."
有谁能举个例子吗?我找不到任何好的相关 posts 或文档来说明在表单中放置什么,这样它就会抓取文件,抓取用户填写的其他表单数据,然后最终将图像发送到google 云存储。
--更新-- :
所以,在 post 之后,我 googled gcs.open,这导致了这个 post:
how to upload image to the cloud storage via app engine?
我相信就后端而言,这可以解决问题,我确实还有一个问题。
重新粘贴问题:
问题:
我不知道图像名称是什么,我想使用现有的,或者可能是随机的。建议?
我应该把这个贴在哪里:enctype="multipart/form-data" ?
编号 2. 会弄乱我的其他表单数据吗?我需要 post 请求
中的这张图片以外的更多信息
回答您的问题:
- 我不知道图片名称是什么,我想用
现有的,或者可能是随机的。有什么建议吗?
我认为这并不重要,只要确保考虑可能的名称冲突以及届时会发生什么。我认为这主要取决于您的应用程序的需求。您始终可以使用随机文件名,并在数据存储中保留对云存储项目的引用旁边的实际文件名。
- 我要把这个贴在哪里:enctype="multipart/form-data" ?
Enctype 是一个表单属性,因此需要在 HTML:
中的表单元素上设置
<form enctype="multipart/form-data" action="/save" ... >
- 编号 2. 会弄乱我的其他表单数据吗?我需要更多信息
post 请求中只有这张图片
不应该。只需添加更多表单输入字段,它们将全部与表单数据一起提交。
您也可以使用签名表格直接上传到 GCS。这样您就不需要 blobstore 或 post 处理程序。您可以使用策略文档控制超时和对象名称。看我的回答here。
先说,
我想我已经阅读了所有似乎与该主题相关的堆栈交换post。*
我想做什么:
- 我正在尝试允许某些用户通过我网站上的表单将图像发送到 google 云存储..
- 将图像发送到云存储的另一个要求是,我需要在数据存储中创建该图像的模型及其相关属性。
我不确定解决此问题的最佳方法是什么,因为..
我读过的方法:
有很多方法可以将图像获取到云存储:
- 通过 blobstore api
- 通过 python 客户端进行云存储:https://cloud.google.com/appengine/docs/python/googlecloudstorageclient/#Python_About_the_client_library
- 通过休息api(我正在考虑json方法)https://cloud.google.com/storage/docs/json_api/v1/how-tos/upload#simple
我读了很多相互矛盾的信息,
而且我读了很多书,我无法直截了当,
然而,
我认为分辨率是:
对于 blobstore:
- blobstore.uploadtocloudstoragethingmethod 可能有也可能没有文件上传限制大小(不,那不是实际的调用或方法名称)2. blobstore 方法听起来像是要被淘汰了??
杰森API:
“但是,客户端库包括 App Engine 优化,因此使用 REST API 可能需要额外的开发时间。注意:App Engine 开发服务器支持云存储客户端。它不支持 REST API。
对于客户端库:
我不知道。到目前为止看起来还不错。这是我正在考虑使用的方法:
"cloudstorage.open(filename, mode='r', content_type=None, options=None, read_buffer_size=storage_api.ReadBuffer.DEFAULT_BUFFER_SIZE, retry_params=None)
In read mode (r) opens the specified Cloud Storage object for read. In write mode w, if the specified file exists, it opens it for an overwrite (append is not supported). If the file doesn't exist, it is created in the specified bucket."
我用的东西:
- Google 应用引擎
- Python(对于处理程序、模型等)
- angularjs 和 jquery(前端)
- json 有时(后端)
- GAE 样板文件(不要问)
我想我会做什么:
- 获取用户图片:
所以,我找到了这个我测试过的表格。它确实从您的计算机中抓取了一个文件:
<form action="<?php echo $upload_url?>" enctype="multipart/form-data"
method="post">
Files to upload: <br> <input type="file" name="uploaded_files" size="40"> <input type="submit" value="Send">
(不,我不能在操作中使用 php 垃圾。我从文档中的某个地方获取它,但我测试了它,它确实抓取了一个文件,不,它赢了'发送,期望它发送是愚蠢的)
- 修改我当前的处理程序(负责在数据存储中创建图像模型)以也使用
此方法:
"cloudstorage.open(filename, mode='r', content_type=None, options=None, read_buffer_size=storage_api.ReadBuffer.DEFAULT_BUFFER_SIZE, retry_params=None)
In read mode (r) opens the specified Cloud Storage object for read. In write mode w, if the specified file exists, it opens it for an overwrite (append is not supported). If the file doesn't exist, it is created in the specified bucket."
我目前遇到的问题
我不知道那个表单是如何工作的,我不知道如何从这个表单中获取正确的信息给处理程序,也不知道处理程序需要什么信息,所以我可以处理它,创建模型(我已经知道如何在数据存储中创建模型,已经这样做了),并且还使用此方法将图像发送到 google 云存储:
"cloudstorage.open(filename, mode='r', content_type=None, options=None, read_buffer_size=storage_api.ReadBuffer.DEFAULT_BUFFER_SIZE, retry_params=None)
In read mode (r) opens the specified Cloud Storage object for read. In write mode w, if the specified file exists, it opens it for an overwrite (append is not supported). If the file doesn't exist, it is created in the specified bucket."
有谁能举个例子吗?我找不到任何好的相关 posts 或文档来说明在表单中放置什么,这样它就会抓取文件,抓取用户填写的其他表单数据,然后最终将图像发送到google 云存储。
--更新-- :
所以,在 post 之后,我 googled gcs.open,这导致了这个 post:
how to upload image to the cloud storage via app engine?
我相信就后端而言,这可以解决问题,我确实还有一个问题。
重新粘贴问题:
问题:
我不知道图像名称是什么,我想使用现有的,或者可能是随机的。建议?
我应该把这个贴在哪里:enctype="multipart/form-data" ?
编号 2. 会弄乱我的其他表单数据吗?我需要 post 请求
中的这张图片以外的更多信息
回答您的问题:
- 我不知道图片名称是什么,我想用 现有的,或者可能是随机的。有什么建议吗?
我认为这并不重要,只要确保考虑可能的名称冲突以及届时会发生什么。我认为这主要取决于您的应用程序的需求。您始终可以使用随机文件名,并在数据存储中保留对云存储项目的引用旁边的实际文件名。
- 我要把这个贴在哪里:enctype="multipart/form-data" ?
Enctype 是一个表单属性,因此需要在 HTML:
中的表单元素上设置<form enctype="multipart/form-data" action="/save" ... >
- 编号 2. 会弄乱我的其他表单数据吗?我需要更多信息 post 请求中只有这张图片
不应该。只需添加更多表单输入字段,它们将全部与表单数据一起提交。
您也可以使用签名表格直接上传到 GCS。这样您就不需要 blobstore 或 post 处理程序。您可以使用策略文档控制超时和对象名称。看我的回答here。