1

我在 Google App Engine 上使用 Python 作为用于视频共享的桌面/移动网络应用程序的后端。我在从 iPhone 上传到 blobstore 时遇到问题。通常页面会在创建上传 URL 后重定向,但在手机上不会发生这种情况。相反,浏览器导航到上传 URL,但没有上传任何内容。

我可以选择一个视频上传就好了,如果它是一个长视频,手机将需要一段时间才能导航到下一页,这似乎暗示正在传输某些内容,但没有任何内容最终出现在 blobstore 中。

使用以下 Python 代码上传视频。

class UploadPage(webapp2.RequestHandler):
  def get(self):
  upload_url = blobstore.create_upload_url('/uploadvideo')
  template_values = {
      'upload_url': upload_url,
  }

  template = JINJA_ENVIRONMENT.get_template('upload.html')
  self.response.write(template.render(template_values))

class UploadHandler(blobstore_handlers.BlobstoreUploadHandler):
  def post(self):
  upload = self.get_uploads()[0]
  video = Videos(content=upload.key())
  video.title = self.request.get('title')
  video.description = self.request.get('description')
  video.ratingDown = 0
  video.ratingUp = 0
  video.creator = users.get_current_user().nickname()
  uniuqeIDFound = False
  newID = random.randint(1000,9999)
  while(uniuqeIDFound == False):
    vids = db.GqlQuery("SELECT * "
                       "FROM Videos ")
    uniuqeIDFound = True                      
  for v in vids:
    if (v.videoID == newID):
      newID = random.randint(1,10000)
      uniuqeIDFound = False
  video.videoID = newID   
  db.put(video)
  self.redirect('/home')

上传页面本身看起来像这样。

<!DOCTYPE html>
<html>
<head>
<title> Upload </title>
<meta charset="utf-8">
<link type="text/css" rel="stylesheet" href="/stylesheets/bootstrap.css" />
<link type="text/css" rel="stylesheet" href="/stylesheets/main.css" />
</head>
<body>
<div class="fill">
<div class="container">
    <ul class="nav nav-tabs">
        <li><a href="/home" data-toggle="tab">Home</a></li>
        <li class="active"><a href="/upload" data-toggle="tab">Upload Video</a></li>
        <li><a href="/logout" data-toggle="tab">Logout</a></li>
        <li><a href="/contact">Contact Us</a></li>
    </ul>
    <h2 class="addColor">Tribal Knowledge</h2><h3 class="addColor">Upload a Video</h3>
    <form class="form-horizontal" action="{{ upload_url }}" method="POST"  enctype="multipart/form-data">
        <textarea placeholder="Title..." name="title" cols="50" rows="1" autofocus="autofocus" required></textarea><br>
        <textarea placeholder="Description..." name="description" cols="50" rows="4" autofocus="autofocus"></textarea><br>
        Upload File: <input type="file" name="file"><br> <input class="btn btn-success" type="submit" name="submit" value="Upload Video">
    </form>
</div>
</div>
</body>
</html>
4

0 回答 0