小编sam*_*amf的帖子

通过POST上传S3浏览器:无法正常处理错误

我正在编写一个应用程序,我希望客户能够直接从浏览器上传到Amazon S3.我可以把这项工作做得很好.但是当出现错误时,我希望比在客户屏幕上展开XML文档更优雅地处理它们.

我有一个我认为可行的方案,但它失败了.这是我正在尝试的:

  1. 创建表单以进行上载,并将表单存储在S3本身上,与表单的"action"属性位于同一域中.
  2. 将客户重定向到此表单.现在他们的浏览器位于https:// <bucket> .s3.amazonaws.com/something.
  3. 该页面包含隐藏的iframe.表单将其目标设置为iframe.
  4. load事件处理程序查看iframe的内容,并对其进行操作.

所以,像这样:

<iframe id="foo" name="foo" style="display: none" />
<form target="foo" action="https://<bucket>.s3.amazonaws.com/">
    <input type="hidden" name="..." value="..." />
    <input type="file" name="file" />
</form>
Run Code Online (Sandbox Code Playgroud)

用这个javascript(使用jquery):

function handler() {
    var message = $("#foo").contents().find('message').text();
    alert(message);
}
$("#foo").load(handler);
Run Code Online (Sandbox Code Playgroud)

使用firebug,我可以看到iframe包含一个XML文档,其中包含一个"消息"节点.但是,.find('message')始终无法在XML文档中找到任何内容.

请注意,表单的操作与文档本身具有相同的域,端口和方案.所以,我认为我不应该违反同源政策.对?但它每次都失败了.这是使用Firefox和谷歌Chrome浏览器.

谢谢你的建议!

jquery amazon-s3 same-origin-policy

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

在Python ctypes中为结构实现offsetof()

我似乎无法为ctypes中的结构实现offsetof.我已经看过ctypesFAQ,但要么它不起作用,要么我无法弄清楚细节.

Python 2.6.4 (r264:75706, Dec 19 2010, 13:04:47) [C] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
>>> from ctypes import *
>>> class Dog(Structure):
...   _fields_ = [('name', c_char_p), ('weight', c_int)]
...   def offsetof(self, field):
...     return addressof(field) - addressof(self)
... 
>>> d = Dog('max', 80)
>>> d.offsetof(d.weight)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 4, in offsetof
TypeError: invalid type
>>> d.offsetof(weight)
Traceback (most …
Run Code Online (Sandbox Code Playgroud)

c python ctypes ffi padding

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

标签 统计

amazon-s3 ×1

c ×1

ctypes ×1

ffi ×1

jquery ×1

padding ×1

python ×1

same-origin-policy ×1