public static void UploadWorldAnchorBlob(AzureStorageDetails storageDetails,
                                                 string identifier, byte[] bits, Action <bool, byte[]> callback)
        {
            Debug.Log(string.Format("Uploading {0:G2}MB blob to Azure",
                                    bits.Length / (1024 * 1024)));

            var headers = new Dictionary <string, string>();

            headers.Add("Content-Type", contentType);

            headers.Add("x-ms-blob-content-disposition",
                        string.Format("attachment; filename=\"{0}\"", identifier));

            headers.Add("x-ms-blob-type", "BlockBlob");

            StorageRequest request = Auth.CreateAuthorizedStorageRequest(
                storageDetails,
                Method.PUT,
                storageDetails.GetFullPathForResource(identifier),
                null,
                headers,
                bits.Length);

            request.AddBody(bits, contentType);

            CoRoutineRunner.Instance.StartCoroutine(EnumerateRequest(request, callback));
        }
        public AuthorizationHeaders(AzureStorageDetails storageDetails, Method method, string resourcePath = "", Dictionary <string, string> queryParams = null, Dictionary <string, string> headers = null, int contentLength = 0)
        {
            string path = resourcePath;

            this.method = method.ToString();
            this.canonicalizedHeaders = new CanonicalizedHeaders(storageDetails.Version, headers);

            if (queryParams != null)
            {
                path = resourcePath + BuildQueryString(queryParams);
            }

            if (headers != null)
            {
                UpdateHeaderValues(headers);
            }

            if (contentLength > 0)
            {
                authHeaders["Content-Length"] = contentLength.ToString();
            }

            // account followed by url encoded resource path, and query params
            this.canonicalizedResource = string.Format("/{0}/{1}", storageDetails.AzureAccountName, path);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Factory method to generate an authorized request URL using query params. (valid up to 15 minutes)
        /// </summary>
        /// <returns>The authorized request.</returns>
        /// <param name="storageDetails">StorageServiceClient</param>
        /// <param name="httpMethod">Http method.</param>
        public static StorageRequest CreateAuthorizedStorageRequest(
            AzureStorageDetails storageDetails, Method method, string resourcePath = "", Dictionary <string, string> queryParams = null, Dictionary <string, string> headers = null, int contentLength = 0)
        {
            string         baseUrl    = storageDetails.PrimaryEndpoint;
            string         requestUrl = UrlHelper.BuildQuery(baseUrl, queryParams, resourcePath);
            StorageRequest request    = new StorageRequest(requestUrl, method);

            request.AuthorizeRequest(storageDetails, method, resourcePath, queryParams, headers, contentLength);
            return(request);
        }
        public static void DownloadWorldAnchorBlob(AzureStorageDetails storageDetails,
                                                   string identifier, Action <bool, byte[]> callback)
        {
            Debug.Log("Downloading blob from Azure storage");

            // The blob service doesn't seem to include a method to just download
            // a blob as a byte[] so doing it here out of the pieces that the
            // service uses internally.
            string url = UrlHelper.BuildQuery(
                storageDetails.PrimaryEndpoint,
                string.Empty,
                storageDetails.GetFullPathForResource(identifier));

            StorageRequest request = new StorageRequest(url, Method.GET);

            CoRoutineRunner.Instance.StartCoroutine(EnumerateRequest(request, callback));
        }
Exemplo n.º 5
0
        public void AuthorizeRequest(AzureStorageDetails storageDetails, Method method, string resourcePath = "", Dictionary <string, string> queryParams = null, Dictionary <string, string> headers = null, int contentLength = 0)
        {
            AuthorizationHeaders authHeaders = new AuthorizationHeaders(storageDetails, method, resourcePath, queryParams, headers, contentLength);
            string stringToSign  = authHeaders.ToString();
            string signature     = GetSignature(storageDetails.AzureKey, stringToSign);
            string authorization = GetAuthorizationHeader(storageDetails.AzureAccountName, signature);

            this.AddHeader("Authorization", authorization);
            this.AddHeader("x-ms-date", authHeaders.MSDate());
            this.AddHeader("x-ms-version", authHeaders.MSVersion());

            if (headers != null)
            {
                this.AddHeaders(headers);
            }

            Debug.Log("Authorized request url:" + this.request.url + "\n\nauthorization: \"" + authorization + "\"\nx-ms-date: " + authHeaders.MSDate() + "\nstringToSign:'" + stringToSign + "'");
        }