Closed hongkunyoo closed 9 years ago
Hi, Thanks for using the angularjs module. Normally the sasToken is prefixed with a question mark when it's retrieved from azure on the server side (How I use it).
How and where do you retrieve the sas token?
Using Azure Mobile Service Javascript Client Library, The client javascript calls the Azure Mobile Service Server Custom API to get the SAS token.
mobileClient.invokeApi("custom_api", {
method : "post",
body : {
.......
}
}).done(function(data) {
// Here is how I get the SAS token.
var sasQueryString = data.result.sasQueryString;
}, function(err) {
console.log(err);
});
exports.post = function(request, response) {
var azure = require('azure');
var qs = require('querystring');
var appSettings = request.service.config.appSettings;
var accountName = appSettings.STORAGE_ACCOUNT_NAME;
var accountKey = appSettings.STORAGE_ACCOUNT_ACCESS_KEY;
var containerName = "mycontainer";
var host = accountName + '.blob.core.windows.net';
var blobName = "myItem";
if ((typeof containerName !== "undefined") && (containerName !== null)) {
// If it does not already exist, create the container
// with public read access for blobs.
var blobService = azure.createBlobService(accountName, accountKey, host);
blobService.createContainerIfNotExists(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(containerName,
blobName, sharedAccessPolicy);
// Set the query string.
var sasQueryString = qs.stringify(sasQueryUrl.queryString);
// Set the full path on the new new item,
// which is used for data binding on the client.
var imageUri = sasQueryUrl.baseUrl + sasQueryUrl.path;
response.send(statusCodes.OK, {sasQueryString : sasQueryString, imageUri: imageUri});
} else {
console.error(error);
response.send(statusCodes.INTERNAL_SERVER_ERROR);
}
});
} else {
response.send(statusCodes.INTERNAL_SERVER_ERROR);
}
};
The server side code is based on the following azure site's tutorials : Azure Site
Instead of adding a question mark at the end of the baseUrl I'd recommend prefixing your sas token with it.
Hello, I realized this angular module is very useful and I'm using it thankfully.
However, there seems to be having an issue while uploading file to blob storage.
I'm not sure whether you intended or not, but anyway the upload method does not work util I add "?" in the back of baseUrl property.
I hope this would help your angular module.
Thanks.