小编Hen*_*teg的帖子

使用node.js为Google云端存储创建已签名的网址,以便从浏览器直接上传

实际的测试用例代码: https ://github.com/HenrikJoreteg/google-cloud-signedurl-test-case

我正在尝试为我的API添加功能,以返回已签名的网址,以便从客户端直接上传到Google云端存储.

Serverside,我正在使用gcloudSDK:

const gcloud = require('gcloud')

const gcs = gcloud.storage({
  projectId: 'my project',
  keyFilename: __dirname + '/path/to/JSON/file.json'
})
const bucket = gcs.bucket('bucket-name')

bucket.file('IMG_2540.png').getSignedUrl({
 action: 'write',
 expires: Date.now() + 60000
}, (error, signedUrl) => {
  if (error == null) {
    console.log(signedUrl)
  }
})
Run Code Online (Sandbox Code Playgroud)

然后在浏览器中我有一个<input type='file'/>我选择了一个文件,然后我尝试将它发布到我的服务器端脚本生成的URL,如下所示:

function upload(blobOrFile, url) {
  var xhr = new XMLHttpRequest();
  xhr.open('PUT', url, true);
  xhr.onload = function(e) {
    console.log('DONE!')
  };
  xhr.upload.onprogress = function(e) {
    if (e.lengthComputable) {
      console.log((e.loaded / e.total) …
Run Code Online (Sandbox Code Playgroud)

javascript node.js google-cloud-storage

7
推荐指数
1
解决办法
2409
查看次数

使用Django在App Engine上存储图像

我正在尝试使用Django在Google App Engine上的db.BlobProperty字段中上传并保存已调整大小的图像.

我认为处理请求的相关部分如下所示:

image = images.resize(request.POST.get('image'), 100, 100)
recipe.large_image = db.Blob(image)
recipe.put()
Run Code Online (Sandbox Code Playgroud)

这似乎是文档中示例的逻辑django等价物:

from google.appengine.api import images

class Guestbook(webapp.RequestHandler):
  def post(self):
    greeting = Greeting()
    if users.get_current_user():
      greeting.author = users.get_current_user()
    greeting.content = self.request.get("content")
    avatar = images.resize(self.request.get("img"), 32, 32)
    greeting.avatar = db.Blob(avatar)
    greeting.put()
    self.redirect('/')
Run Code Online (Sandbox Code Playgroud)

(来源:http://code.google.com/appengine/docs/python/images/usingimages.html#Transform)

但是,我不断收到错误消息:NotImageError/Empty image data.

并指这一行:

image = images.resize(request.POST.get('image'), 100, 100)
Run Code Online (Sandbox Code Playgroud)

我无法获取图像数据.好像它没有被上传,但我无法弄清楚原因.我的表单有enctype ="multipart/form-data"等等.我认为我所指的图像数据有些不对劲."request.POST.get('image')"但我无法弄清楚如何引用它.有任何想法吗?

提前致谢.

django google-app-engine

5
推荐指数
1
解决办法
4092
查看次数