Blobstore 上传 +阿贾克斯/替代方案

发布于 2024-12-01 13:36:39 字数 501 浏览 1 评论 0原文

下面的代码可以完美运行。我唯一关心的是我想将下面的内容转换为 AJAX/alternative,这样就不需要刷新整个页面来提交此请求。

如果可能的话,还包括加载进度条等。

<form action="{{ upload_url }}" method="POST" enctype="multipart/form-data">

        Upload File: <input type="file" name="file"> <br> 
        <input type="submit" name="submit" value="Submit"> 

        <input type="hidden" name="data1" value="{{ data1 }}">
        <input type="hidden" name="data1" value="{{ data2 }}">

</form>

The following code works perfectly. My only concern is that I wanna convert below to AJAX/alternative, so that it doesn't need to refresh the whole page to submit this request.

If possible, to also include loading progress bar etc.

<form action="{{ upload_url }}" method="POST" enctype="multipart/form-data">

        Upload File: <input type="file" name="file"> <br> 
        <input type="submit" name="submit" value="Submit"> 

        <input type="hidden" name="data1" value="{{ data1 }}">
        <input type="hidden" name="data1" value="{{ data2 }}">

</form>

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

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

发布评论

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

评论(1

总以为 2024-12-08 13:36:39

看一下一些用于 AJAX 上传的 JS 解决方案 - 具体来说,Plupload 可以连接到 App Engine blobstore,为您提供多重上传支持、AJAX 上传以及上传小部件/进度条等选项。

事实上,@NickJohnson 拥有完整的博客文章 指导您完成步骤。

其要点是:

1) 下载并安装 Plupload

2) 创建一个返回生成的上传 URL 的处理程序。像这样的事情:

from google.appengine.ext import webapp
from google.appengine.api import blobstore

class BlobstoreURLResponder(webapp.RequestHandler):

    """ Mapped to the URL /get_upload_url """

    def get(self):
        self.response.headers['Content-Type'] = 'text/plain'
        self.request.out.write(blobstore.create_upload_url('/blobstore/passthrough'))

3) 在上传文件之前连接 Plupload 以获取 blob 上传 URL

uploader.bind('UploadFile', function(up, file) {
    $.ajax({
        url: '/get_upload_url',
        async: false,
        success: function(data) {
          up.settings.url = data;
        },
    });

有关更详细的说明,请查看该博客文章。 Nick 有一个非常棒的演练,它绝对帮助我设置了 Plupload + Blobstore。

Take a look at some JS solutions for AJAX upload - specifically, Plupload can be hooked up to work with the App Engine blobstore, giving you multiupload support, AJAX upload, and options for upload widgets/progress bars/etc.

In fact, @NickJohnson has a full blog post guiding you through the steps.

The gist of it is:

1) Download and install Plupload

2) Create a handler that returns a generated upload URL. Something like this:

from google.appengine.ext import webapp
from google.appengine.api import blobstore

class BlobstoreURLResponder(webapp.RequestHandler):

    """ Mapped to the URL /get_upload_url """

    def get(self):
        self.response.headers['Content-Type'] = 'text/plain'
        self.request.out.write(blobstore.create_upload_url('/blobstore/passthrough'))

3) Hook up Plupload to get a blob upload URL before uploading a file

uploader.bind('UploadFile', function(up, file) {
    $.ajax({
        url: '/get_upload_url',
        async: false,
        success: function(data) {
          up.settings.url = data;
        },
    });

For more detailed instructions, take a look at that blog post. Nick has an awesome walkthrough that definitely helped me get set up with Plupload + Blobstore.

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