我已将一些文件上传到S3存储桶.为了限制访问,我设置了一个带有HTTP referrer的存储桶策略,允许从Sharepoint站点重定向.我使用Sharepoint是因为将访问S3文件的用户的授权.这很好用.但只有Firefox!
在搜索之后,似乎其他浏览器(我尝试过Chrome和Edge)会阻止HTTP引荐来源吗?是什么赋予了?
我当然可以通过AWS和IAM进行访问,但这会让事情变得复杂一些.此时,使用O365的访问控制似乎是最简单的.但我不想强迫客户使用Firefox.
(注意:根据您可能会问的原因,为什么不使用Sharepoint来托管文件.我有一个静态的HTML,并且在S3上设置起来很容易.但也许在Sharepoint上有一些替代方案?)
我有23位表示为字符串,我需要将此字符串写为4字节的二进制文件.最后一个字节始终为0.以下代码可以工作(Python 3.3),但它感觉不是很优雅(我对Python和编程很新).你有什么提示让它变得更好吗?似乎for循环可能有用,但如何在循环内进行切片而不会得到IndexError?请注意,当我将这些位提取到一个字节时,我会反转位顺序.
from array import array
bin_array = array("B")
bits = "10111111111111111011110" #Example string. It's always 23 bits
byte1 = bits[:8][::-1]
byte2 = bits[8:16][::-1]
byte3 = bits[16:][::-1]
bin_array.append(int(byte1, 2))
bin_array.append(int(byte2, 2))
bin_array.append(int(byte3, 2))
bin_array.append(0)
with open("test.bnr", "wb") as f:
f.write(bytes(bin_array))
# Writes [253, 255, 61, 0] to the file
Run Code Online (Sandbox Code Playgroud) 我在交互模式下测试了sys.stdout.write; 为什么我会在数字后面加上'额外'1和2?如果我从文件中运行代码,我会在Windows机器上获得预期的输出(1234 ...)Python 3.3
>>> import sys
>>> for i in range(15):
... sys.stdout.write(str(i))
...
01
11
21
31
41
51
61
71
81
91
102
112
122
132
142
>>>
Run Code Online (Sandbox Code Playgroud)