Ejemplo n.º 1
0
        /// <summary>
        /// Upload file.
        /// </summary>
        /// <param name="url"></param>
        /// <param name="fileId"></param>
        /// <param name="filename"></param>
        /// <param name="inputStream"></param>
        /// <param name="ttl"></param>
        /// <returns></returns>
        public async Task <FileHandleStatus> UploadFile(string url, string fileId, string filename, Stream inputStream, string ttl)
        {
            url = url + "/" + fileId;
            if (!string.IsNullOrEmpty(ttl))
            {
                url = url + "?ttl=" + ttl;
            }
            var request = new HttpRequestMessage(HttpMethod.Post, new Uri(url));

            JsonResponse jsonResponse;

            using (var content = new MultipartFormDataContent("Upload----" + DateTime.Now.ToString(CultureInfo.InvariantCulture)))
            {
                content.Add(new StreamContent(inputStream), Path.GetFileNameWithoutExtension(filename), filename);
                request.Content = content;
                jsonResponse    = await _connection.FetchJsonResultByRequest(request);
            }

            ConvertResponseStatusToException((int)jsonResponse.StatusCode, url, fileId, false, false, false, false);

            var result = JsonConvert.DeserializeObject <FileHandleStatus>(jsonResponse.Json);

            result.LastModified = DateTime.UtcNow.ToFileTimeUtc();
            result.FileId       = fileId;
            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Assign a file key.
        /// </summary>
        /// <param name="values"></param>
        /// <returns></returns>
        public async Task <AssignFileKeyResult> AssignFileKey(AssignFileKeyParams values)
        {
            CheckConnection();
            var url     = _connection.LeaderUrl + RequestPathStrategy.AssignFileKey + values.ToUrlParams();
            var request = new HttpRequestMessage(
                HttpMethod.Get,
                new Uri(url)
                );
            var jsonResponse = await _connection.FetchJsonResultByRequest(request);

            var obj = JsonConvert.DeserializeObject <AssignFileKeyResult>(jsonResponse.Json, Settings.JsonSerializerSettings);

            return(obj);
        }