GetObjectUrl() public static method

public static GetObjectUrl ( string storageUrl, string containerId, string objectId, string>.Dictionary queryParams = null ) : string
storageUrl string
containerId string
objectId string
queryParams string>.Dictionary
return string
Esempio n. 1
0
        public Task <SwiftResponse> GetObject(string containerId, string objectId, Dictionary <string, string> headers = null, Dictionary <string, string> queryParams = null)
        {
            return(AuthorizeAndExecute(async(auth) =>
            {
                var url = SwiftUrlBuilder.GetObjectUrl(auth.StorageUrl, containerId, objectId, queryParams);

                var request = new HttpRequestMessage(HttpMethod.Get, url);

                FillRequest(request, auth, headers);

                try
                {
                    var response = await _client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false);

                    var result = GetResponse <SwiftResponse>(response);

                    if (response.IsSuccessStatusCode)
                    {
                        result.Stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
                    }

                    return result;
                }
                catch (Exception ex)
                {
                    return GetExceptionResponse <SwiftResponse>(ex, url);
                }
            }));
        }
Esempio n. 2
0
        public Task <SwiftResponse> PutObject(string containerId, string objectId, byte[] data, Dictionary <string, string> headers = null, Dictionary <string, string> queryParams = null)
        {
            return(AuthorizeAndExecute(async(auth) =>
            {
                var url = SwiftUrlBuilder.GetObjectUrl(auth.StorageUrl, containerId, objectId, queryParams);

                var request = new HttpRequestMessage(HttpMethod.Put, url);

                FillRequest(request, auth, headers);

                try
                {
                    request.Content = new ByteArrayContent(data);

                    using (var response = await _client.SendAsync(request).ConfigureAwait(false))
                    {
                        var result = GetResponse <SwiftResponse>(response);

                        // container not found
                        if (result.StatusCode == HttpStatusCode.NotFound)
                        {
                            return await EnsurePutContainer(containerId, () => PutObject(containerId, objectId, data, headers, queryParams)).ConfigureAwait(false);
                        }

                        return result;
                    }
                }
                catch (Exception ex)
                {
                    return GetExceptionResponse <SwiftResponse>(ex, url);
                }
            }));
        }
Esempio n. 3
0
        public Task <SwiftResponse> PostObject(string containerId, string objectId, Dictionary <string, string> headers = null)
        {
            return(AuthorizeAndExecute(async(auth) =>
            {
                var url = SwiftUrlBuilder.GetObjectUrl(auth.StorageUrl, containerId, objectId);

                var request = new HttpRequestMessage(HttpMethod.Post, url);

                FillRequest(request, auth, headers);

                try
                {
                    using (var response = await _client.SendAsync(request).ConfigureAwait(false))
                    {
                        return GetResponse <SwiftResponse>(response);
                    }
                }
                catch (Exception ex)
                {
                    return GetExceptionResponse <SwiftResponse>(ex, url);
                }
            }));
        }