我需要有关配置精细上传器以便使用Azure Blob存储的过程的深入信息(非常感谢代码示例)。
目前,我正面临着了解精细上传者的控制流程和整体行为的问题。我已经在精细上传网站上查看了文档,但我需要在没有知识假设的情况下描述更多信息。
截至目前,我的解决方案架构如下:
我的解决方案包括服务器(SRV),客户端(CL)和天蓝色blob存储容器(AC)。我想做的是让CL将jpg文件上传到AC,为了做到这一点,我目前正在为CL提供blob存储容器的SAS签名。
我目前无法这样做(我认为这可能无法正确实施)。精细上传器的GET请求处理程序如下:
@login_required
@app.route('/sas', methods=['GET'])
def sas():
container_name = '/asilverman/picdepot/'
sas = SharedAccessSignature(account_name=app.config['AZURE_ACCOUNT'],account_key=app.config['AZURE_KEY'])
access_policy = AccessPolicy()
access_policy.start = '2015-08-22T21:00:00Z' #(datetime.datetime.utcnow() + datetime.timedelta(seconds=-120)).strftime('%Y-%m-%d') #T%H:%M:%SZ
access_policy.expiry = '2015-08-25T21:00:00Z' #(datetime.datetime.utcnow() + datetime.timedelta(seconds=120)).strftime('%Y-%m-%dT%H:%M:%SZ')
access_policy.permission = 'w'
sap = SharedAccessPolicy(access_policy)
sas_token = sas.generate_signed_query_string(container_name, 'c', sap)
return request.args['bloburi'] + '?' + sas_token
我的主要Blob服务端点是:https://asilverman.blob.core.windows.net/
我希望存储图片文件的容器的名称是:picdepot
我的上传器配置如下:
var uploader = new qq.azure.FineUploader({
debug: true,
element: document.getElementById("fine-uploader"),
request: {
endpoint: 'https://asilverman.blob.core.windows.net/picdepot'
},
cors: {
//all requests are expected to be cross-domain requests
expected: true,
sendCredentials: true
},
signature: {
customHeaders: {'Access-Control-Allow-Origin': true},
endpoint: '/sas'
},
uploadSuccess: {
endpoint: ''
},
scaling: {
sendOriginal: false,
sizes: [
{name: "", maxSize: 800}
]
},
validation: {
allowedExtensions: ['jpeg', 'jpg', 'png']
}
});
我的CORS配置如下:
Storage Account: https://asilverman.blob.core.windows.net/
Cors.CorsRules.Count : 1
corsRule[index] : 0
corsRule.AllowedHeaders : Content-Type
corsRule.AllowedHeaders : Access-Control-Allow-Origin
corsRule.AllowedHeaders : x-ms-*
corsRule.AllowedMethods : Get, Put, Delete
corsRule.AllowedOrigins : *
corsRule.ExposedHeaders : Access-Control-Allow-Origin
corsRule.MaxAgeInSeconds : 432000
DefaultServiceVersion : 2013-08-15
HourMetrics.MetricsLevel : None
HourMetrics.RetentionDays :
HourMetrics.Version : 1.0
Logging.LoggingOperations : None
Logging.RetentionDays :
Logging.Version : 1.0
MinuteMetrics.MetricsLevel : None
MinuteMetrics.RetentionDays :
MinuteMetrics.Version : 1.0
New Properties:
Cors.CorsRules.Count : 1
corsRule[index] : 0
corsRule.AllowedHeaders : *
corsRule.AllowedMethods : Get, Put, Delete
corsRule.AllowedOrigins : *
corsRule.ExposedHeaders : *
corsRule.MaxAgeInSeconds : 432000
DefaultServiceVersion : 2013-08-15
HourMetrics.MetricsLevel : None
HourMetrics.RetentionDays :
HourMetrics.Version : 1.0
Logging.LoggingOperations : None
Logging.RetentionDays :
Logging.Version : 1.0
MinuteMetrics.MetricsLevel : None
MinuteMetrics.RetentionDays :
MinuteMetrics.Version : 1.0
答案 0 :(得分:-1)
我目前无法这样做(我认为这可能无法正确实施)。
return request.args['bloburi'] + '?' + sas_token
@asilveman,如果你能提供这个实现的输出会更好,根据我的理解,URL的标准格式是:
storage_url+container_name + '/' + blob_name+'?'+qry_string
虽然这里的qry_string是我们需要生成的共享访问签名网址。
参考代码段供您参考
from azure.storage import AccessPolicy
from azure.storage.sharedaccesssignature import (
SharedAccessPolicy,
SharedAccessSignature,
)
DEV_STORAGE_ACCOUNT_NAME ="xxxxx"
DEV_STORAGE_ACCOUNT_KEY ="xxxxx"
CONTAINER_NAME='xxxxx'
STORAGE_URL = 'xxxxx'
def generate_signature_blob(dev_storage_account_name,dev_storage_account_key,container_name):
sas = SharedAccessSignature(account_name=dev_storage_account_name,account_key=dev_storage_account_key)
accss_plcy = AccessPolicy()
accss_plcy.expiry = '2016-10-12'
accss_plcy.permission = 'w'
sap = SharedAccessPolicy(accss_plcy)
sasToken = sas.generate_signed_query_string(container_name,'container',sap)
return sas._convert_query_string(sasToken).replace("container","c")
生成共享访问签名网址:
qry_string = generate_signature_blob(DEV_STORAGE_ACCOUNT_NAME,DEV_STORAGE_ACCOUNT_KEY,CONTAINER_NAME)
在Python项目中,您可以利用urllib2来发出这样的PUT请求 import urllib2
def put_blob(storage_url,container_name, blob_name,qry_string,x_ms_blob_type):
opener = urllib2.build_opener(urllib2.HTTPHandler)
request = urllib2.Request(storage_url+container_name + '/' + blob_name+'?'+qry_string, data='Hello World!!')
request.add_header('x-ms-blob-type', x_ms_blob_type)
request.get_method = lambda: 'PUT'
opener.open(request)
然后通过调用
将blob上传到Azure存储put_blob(STORAGE_URL,CONTAINER_NAME,"sample.jpg",qry_string,"BlockBlob")
您可能还想参考由Prashanth创建的good guidance,如果您有任何其他问题,请随时告诉我们。