1

I am creating a project on google app engine. Here I am trying to upload a file to blobstore. I have an html file with multiple forms, where each form has a file upload button

<input type="file">

Now as soon as user selects a file using this button the file must start uploading to GAE blobstore.
I have the python code which can do this uploading stuff but I am not able to link my backend (python) code to the file I've browsed. Also, as there are multiple forms the page must not get refreshed.

I have found a solution to page refresh in google closure(using a pop up), but it is not desire in my project. I believe there is no other way in closure library.

I am trying to do it using ajax call but my very limited knowledge of ajax is preventing me to get the dsired results.

Using JQUERY is not an option.

I hope my question is clear, please revert back if not.

Any help is much appreciated.

Thanks

4

2 回答 2

2

Google Closure 提供了一个 IframeIo 类,可以发布您的文件(无需刷新页面),此处提供文档,http: //closure-library.googlecode.com/svn/docs/class_goog_net_IframeIo.html

我们在 IframeIo(在 BSD 许可下可用)上实现了一个包装器,以在用户选择文件时向用户显示文件上传输入和 URL 的帖子。来源:https://code.google.com/p/prestans/source/browse/trunk/client/closure/ui/IframeFileUpload.js

处理成功/失败代码有点棘手,具体取决于您从 Blobstore 文件上传处理程序返回的内容。

于 2012-07-04T04:47:41.763 回答
1

我使用的是使用输入/文件控制的onchange。onChange 返回控件和 mime 类型。在 onchange 中,您可以访问控件的 filelist 数组以获取文件名。使用文件名,您可以使用 FileReader 加载实际数据。可以使用 xhr post(并将其转换为 base64)将此数据上传到服务器。就像是:

function onChange(control, mimetype) {
var f = control.files;
if (f.length) {
  var reader = new FileReader;
  reader.onload = function() {
    // Post using xhr
  }
  reader.readAsBinaryString(f)
}

请注意,并非所有浏览器上都存在 FileReader 对象...(Chrome 确实支持它!)

于 2012-07-03T22:33:25.623 回答