Ejemplo n.º 1
0
        public async Task <ImagekitResponse> UploadAsync(byte[] file, AuthParamResponse clientAuth)
        {
            Uri apiEndpoint = new Uri(Utils.GetUploadApi());

            var response = await Utils.PostUploadAsync(apiEndpoint, getUploadData(clientAuth), file).ConfigureAwait(false);

            var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

            ImagekitResponse resp = JsonConvert.DeserializeObject <ImagekitResponse>(responseContent);

            resp.StatusCode = (int)response.StatusCode;
            return(resp);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Upload the file as byte[].
        /// </summary>
        /// <param name="file">File input as byte Array.</param>
        /// <returns>The response body of the upload request.</returns>
        public async Task <ImagekitResponse> UploadAsync(byte[] file)
        {
            Uri apiEndpoint = new Uri(Utils.GetUploadApi());

            HttpResponseMessage response = await Utils.PostUploadAsync(apiEndpoint, getUploadData(), file, (string)options["privateKey"]).ConfigureAwait(false);

            var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

            ImagekitResponse resp = JsonConvert.DeserializeObject <ImagekitResponse>(responseContent);

            resp.StatusCode   = (int)response.StatusCode;
            resp.XIkRequestId = response.Headers.FirstOrDefault(x => x.Key == "x-ik-requestid").Value?.First();
            return(resp);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Upload the file at the path.
        /// </summary>
        /// <param name="filePath">The local file path or remote URL for the file.</param>
        /// <returns>The response body of the upload request.</returns>
        public async Task <ImagekitResponse> UploadAsync(string filePath, AuthParamResponse clientAuth)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                throw new ArgumentException(errorMessages.MISSING_UPLOAD_FILE_PARAMETER);
            }
            Uri apiEndpoint = new Uri(Utils.GetUploadApi());

            var response = await Utils.PostUploadAsync(apiEndpoint, getUploadData(clientAuth), filePath).ConfigureAwait(false);

            var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

            ImagekitResponse resp = JsonConvert.DeserializeObject <ImagekitResponse>(responseContent);

            resp.StatusCode = (int)response.StatusCode;
            return(resp);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// The local file fullpath or remote URL for the file.
        /// </summary>
        /// <param name="file">The local file path or remote URL for the file.</param>
        /// <returns>The response body of the upload request.</returns>
        public async Task <ImagekitResponse> UploadAsync(string file)
        {
            if (string.IsNullOrEmpty(file))
            {
                throw new ArgumentException(errorMessages.MISSING_UPLOAD_FILE_PARAMETER);
            }
            Uri apiEndpoint = new Uri(Utils.GetUploadApi());

            HttpResponseMessage response = await Utils.PostUploadAsync(apiEndpoint, getUploadData(), file, (string)options["privateKey"]).ConfigureAwait(false);

            var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

            ImagekitResponse resp = JsonConvert.DeserializeObject <ImagekitResponse>(responseContent);

            resp.StatusCode   = (int)response.StatusCode;
            resp.XIkRequestId = response.Headers.FirstOrDefault(x => x.Key == "x-ik-requestid").Value?.First();
            return(resp);
        }