Пример #1
0
        private IEnumerator PutBlobBytes(Action <RestResponse> callback, byte[] bytes, string resourcePath, string filename, string contentType)
        {
            int contentLength = bytes.Length;
            // TODO: check size is ok?
            Dictionary <string, string> headers = new Dictionary <string, string>();

            string file = Path.GetFileName(filename);

            headers.Add("Content-Type", contentType);
            headers.Add("x-ms-blob-content-disposition", string.Format("attachment; filename=\"{0}\"", file));
            headers.Add("x-ms-blob-type", "BlockBlob");

            string filePath = resourcePath.Length > 0 ? resourcePath + "/" + file : file;

            StorageRequest request = Auth.CreateAuthorizedStorageRequest(client, Method.PUT, filePath, null, headers, contentLength);

            // add body
            request.AddBody(bytes, contentType);

            yield return(request.Request.Send());

#if UNITY_EDITOR
            while (request.Request.responseCode == -1L)
            {
            }
#endif

            request.Result(callback);
        }
Пример #2
0
        public static StorageRequest GetAuthorizedStorageRequestAssetBundle(StorageServiceClient client, string resourcePath = "", Dictionary <string, string> queryParams = null, Dictionary <string, string> headers = null, int contentLength = 0)
        {
            string         requestUrl = RequestUrl(client, queryParams, resourcePath);
            StorageRequest request    = new StorageRequest(UnityWebRequest.GetAssetBundle(requestUrl));

            request.AuthorizeRequest(client, Method.GET, resourcePath, queryParams, headers, contentLength);
            return(request);
        }
Пример #3
0
        public static StorageRequest GetAuthorizedStorageRequestAudioClip(StorageServiceClient client, string resourcePath = "", Dictionary <string, string> queryParams = null, Dictionary <string, string> headers = null, int contentLength = 0, AudioType audioType = AudioType.WAV)
        {
            string         requestUrl = RequestUrl(client, queryParams, resourcePath);
            StorageRequest request    = new StorageRequest(UnityWebRequestMultimedia.GetAudioClip(requestUrl, audioType));

            request.AuthorizeRequest(client, Method.GET, resourcePath, queryParams, headers, contentLength);
            return(request);
        }
Пример #4
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="client">StorageServiceClient</param>
        /// <param name="httpMethod">Http method.</param>
        public static StorageRequest CreateAuthorizedStorageRequest(StorageServiceClient client, Method method, string resourcePath = "", Dictionary <string, string> queryParams = null, Dictionary <string, string> headers = null, int contentLength = 0)
        {
            string         requestUrl = RequestUrl(client, queryParams, resourcePath);
            StorageRequest request    = new StorageRequest(requestUrl, method);

            request.AuthorizeRequest(client, method, resourcePath, queryParams, headers, contentLength);
            return(request);
        }
Пример #5
0
        public IEnumerator GetImageBlob(Action <IRestResponse <Texture> > callback, string resourcePath = "")
        {
            StorageRequest request = Auth.GetAuthorizedStorageRequestTexture(client, resourcePath);

            yield return(request.Send());

            request.GetTexture(callback);
        }
Пример #6
0
        public IEnumerator GetXmlBlob <T>(Action <IRestResponse <T> > callback, string resourcePath = "")
        {
            StorageRequest request = Auth.GetAuthorizedStorageRequest(client, resourcePath);

            yield return(request.Send());

            request.ParseXML <T>(callback);
        }
Пример #7
0
        public IEnumerator GetAssetBundle(Action <IRestResponse <AssetBundle> > callback, string resourcePath = "")
        {
            StorageRequest request = Auth.GetAuthorizedStorageRequestAssetBundle(client, resourcePath);

            yield return(request.Send());

            request.GetAssetBundle(callback);
        }
Пример #8
0
        public IEnumerator GetTextBlob(Action <RestResponse> callback, string resourcePath = "", Dictionary <string, string> queryParams = null, Dictionary <string, string> headers = null, int contentLength = 0)
        {
            StorageRequest request = Auth.GetAuthorizedStorageRequest(client, resourcePath, queryParams, headers, contentLength);

            yield return(request.Send());

            request.GetText(callback);
        }
Пример #9
0
        public IEnumerator DeleteBlob(Action <RestResponse> callback, string resourcePath, string filename)
        {
            string         filePath = resourcePath.Length > 0 ? resourcePath + "/" + filename : filename;
            StorageRequest request  = Auth.CreateAuthorizedStorageRequest(client, Method.DELETE, filePath);

            yield return(request.Send());

            request.Result(callback);
        }
Пример #10
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="client">StorageServiceClient</param>
        /// <param name="httpMethod">Http method.</param>
        public static StorageRequest CreateAuthorizedStorageRequest(StorageServiceClient client, Method method, string resourcePath = "", Dictionary <string, string> queryParams = null, Dictionary <string, string> headers = null, int contentLength = 0)
        {
            string         baseUrl    = client.PrimaryEndpoint();
            string         requestUrl = UrlHelper.BuildQuery(baseUrl, queryParams, resourcePath);
            StorageRequest request    = new StorageRequest(requestUrl, method);

            request.AuthorizeRequest(client, method, resourcePath, queryParams, headers, contentLength);
            return(request);
        }
Пример #11
0
        public IEnumerator GetTextBlob(Action <RestResponse> callback, string resourcePath = "")
        {
            // public request
            string         url     = UrlHelper.BuildQuery(client.SecondaryEndpoint(), "", resourcePath);
            StorageRequest request = new StorageRequest(url, Method.GET);

            yield return(request.Request.Send());

            request.Result(callback);
        }
Пример #12
0
        /// <summary>
        /// Lists all of the blobs in a container.
        /// </summary>
        /// <returns>The containers.</returns>
        /// <param name="">.</param>
        public IEnumerator ListBlobs(Action <IRestResponse <BlobResults> > callback, string resourcePath = "")
        {
            Dictionary <string, string> queryParams = new Dictionary <string, string>();

            queryParams.Add("comp", "list");
            queryParams.Add("restype", ResType.container.ToString());
            StorageRequest request = Auth.CreateAuthorizedStorageRequest(client, Method.GET, resourcePath, queryParams);

            yield return(request.Send());

            request.ParseXML <BlobResults>(callback);
        }
Пример #13
0
        public static StorageRequest CreateAuthorizedStorageRequest(StorageServiceClient client, Method method, byte[] data, string resourcePath = "", Dictionary <string, string> queryParams = null, Dictionary <string, string> headers = null, int contentLength = 0)
        {
            if (data == null)
            {
                throw new ArgumentNullException();
            }

            string         requestUrl = RequestUrl(client, queryParams, resourcePath);
            StorageRequest request    = new StorageRequest(requestUrl, method, data);

            request.AuthorizeRequest(client, method, resourcePath, queryParams, headers, contentLength);
            return(request);
        }