上传图片蔚蓝的Blob存储 [英] uploading image to azure blob storage
问题描述
我知道这个问题可能是PTED为重复间$ P $,但我根本无法得到blop服务工作。我按照标准的<一个href=\"http://www.windowsazure.com/en-us/documentation/articles/mobile-services-windows-phone-upload-data-blob-storage/\"相对=nofollow>例如MSDN上。我在code语言实现的,但随后的例子。我可以让我MobileService,在这个例子中提供的脚本,插入开放性质的斑点。然后我用这个code将图像上传到Blob存储:
I know this question can be interpreted as a duplicate, but I can simply not get the blop service working. I have followed the standard example on msdn. I have implemented in my code but followed the example. I can get my MobileService, with the supplied script in the example, to insert a blob with open properties. I then use this code to upload an image to the blob storage:
BitmapImage bi = new BitmapImage();
MemoryStream stream = new MemoryStream();
if (bi != null)
{
WriteableBitmap bmp = new WriteableBitmap((BitmapSource)bi);
bmp.SaveJpeg(stream, bmp.PixelWidth, bmp.PixelHeight, 0, 100);
}
if (!string.IsNullOrEmpty(uploadImage.SasQueryString))
{
// Get the URI generated that contains the SAS
// and extract the storage credentials.
StorageCredentials cred = new StorageCredentials(uploadImage.SasQueryString);
var imageUri = new Uri(uploadImage.ImageUri);
// Instantiate a Blob store container based on the info in the returned item.
CloudBlobContainer container = new CloudBlobContainer(
new Uri(string.Format("https://{0}/{1}",
imageUri.Host, uploadImage.ContainerName)), cred);
// Upload the new image as a BLOB from the stream.
CloudBlockBlob blobFromSASCredential = container.GetBlockBlobReference(uploadImage.ResourceName);
await blobFromSASCredential.UploadFromStreamAsync(stream);//error!
// When you request an SAS at the container-level instead of the blob-level,
// you are able to upload multiple streams using the same container credentials.
stream = null;
}
我得到一个错误在这个code在点标记错误,并出现以下错误:
I am getting an error in this code at the point marked error, with the following error:
+ ex {Microsoft.WindowsAzure.Storage.StorageException: The remote server returned an error: NotFound. ---> System.Net.WebException: The remote server returned an error: NotFound. ---> System.Net.WebException: The remote server returned an error: NotFound.
我不明白,因为code,从脚本返回的字符串是:
Which I do not understand since the code that returns the string from the script is:
// Generate the upload URL with SAS for the new image.
var sasQueryUrl = blobService.generateSharedAccessSignature(item.containerName,
item.resourceName, sharedAccessPolicy);
// Set the query string.
item.sasQueryString = qs.stringify(sasQueryUrl.queryString);
// Set the full path on the new new item,
// which is used for data binding on the client.
item.imageUri = sasQueryUrl.baseUrl + sasQueryUrl.path;
当然,这也显示了,我不完全掌握Blob存储的建设。因此,任何帮助将是AP preciated。
Of course this also depicts that I do not completely grasp the construction of the blob storage. And therefore any help would be appreciated.
注释阐述
从服务器code应该为至少5分钟创建一个公共注释。因此不会成为问题。我的服务器脚本是一样的<一个href=\"http://www.windowsazure.com/en-us/documentation/articles/mobile-services-windows-phone-upload-data-blob-storage/\"相对=nofollow>的链接。但在这里复制:
var azure = require('azure');
var qs = require('querystring');
var appSettings = require('mobileservice-config').appSettings;
function insert(item, user, request) {
// Get storage account settings from app settings.
var accountName = appSettings.STORAGE_ACCOUNT_NAME;
var accountKey = appSettings.STORAGE_ACCOUNT_ACCESS_KEY;
var host = accountName + '.blob.core.windows.net';
if ((typeof item.containerName !== "undefined") && (
item.containerName !== null)) {
// Set the BLOB store container name on the item, which must be lowercase.
item.containerName = item.containerName.toLowerCase();
// If it does not already exist, create the container
// with public read access for blobs.
var blobService = azure.createBlobService(accountName, accountKey, host);
blobService.createContainerIfNotExists(item.containerName, {
publicAccessLevel: 'blob'
}, function(error) {
if (!error) {
// Provide write access to the container for the next 5 mins.
var sharedAccessPolicy = {
AccessPolicy: {
Permissions: azure.Constants.BlobConstants.SharedAccessPermissions.WRITE,
Expiry: new Date(new Date().getTime() + 5 * 60 * 1000)
}
};
// Generate the upload URL with SAS for the new image.
var sasQueryUrl =
blobService.generateSharedAccessSignature(item.containerName,
item.resourceName, sharedAccessPolicy);
// Set the query string.
item.sasQueryString = qs.stringify(sasQueryUrl.queryString);
// Set the full path on the new new item,
// which is used for data binding on the client.
item.imageUri = sasQueryUrl.baseUrl + sasQueryUrl.path;
} else {
console.error(error);
}
request.execute();
});
} else {
request.execute();
}
}
与图像的想法是,该应用的其他用户应能够访问它们。据我了解我已公开,但只有5分钟写公开。对于BLOB我保存在一个mobileservice表,其中用户需要进行身份验证的URL,我想在存储相同的安全。但不知道这是否完成?我为所有的愚蠢的问题抱歉,但我一直没能解决它在我自己的,所以我必须看起来愚蠢:)
The idea with the pictures is that other users of the app should be able to access them. As far as I understand I have made it public, but only write public for 5 minutes. The url for the blob I save in a mobileservice table, where the user needs to be authenticated, I would like the same safety on the storage. But do not know if this is accomplished? I am sorry for all the stupid questions, but I have not been able to solve it on my own so I have to "seem" stupid :)
推荐答案
如果有人在这里需要帮助的结束。对我来说,问题是URI。它应该是http和没有使用https。然后有没有错误上传。
If someone ends up in here needing help. The problem for me was the uri. It should have been http and not https. Then there were no error uploading.
但显示即使在从工具箱中的测试图像控制图像,没有成功。问题是我必须设置流开始时:
But displaying the image even on a test image control from the toolbox, did not succeed. The problem was I had to set the stream to the begining:
stream.Seek(0, SeekOrigin.Begin);
接着上传工作,并能够检索数据。
Then the upload worked and was able to retrieve the data.
这篇关于上传图片蔚蓝的Blob存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!