FileSync/FileSync/B2SDK.cs
/// <summary>
/// Gets Upload Url for pushing files to a specific bucket.
/// </summary>
/// <param name="bucketId"> Id for bucket to get upload url for</param>
/// <returns>string upload url</returns>
Gets Upload Url for pushing files to a specific bucket.
Gets Upload Url for pushing files to a specific bucket .
public string b2_get_upload_url(string bucketId)
        {
            if (!checkStringParamsNotEmpty(new string[] { bucketId }) || !authorized)
            {
                return "";
            }
            if (uploadUrls.ContainsKey(bucketId))
            {
                return uploadUrls[bucketId];
            }
            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(apiUrl + "/b2api/v1/b2_get_upload_url");
            string body = "{\"bucketId\":\"" + bucketId + "\"}";
            var data = Encoding.UTF8.GetBytes(body);
            webRequest.Method = "POST";
            webRequest.Headers.Add("Authorization", authorizationToken);
            webRequest.ContentType = "application/json; charset=utf-8";
            webRequest.ContentLength = data.Length;
            using (var stream = webRequest.GetRequestStream())
            {
                stream.Write(data, 0, data.Length);
                stream.Close();
            }
            WebResponse response = (HttpWebResponse)webRequest.GetResponse();
            var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
            response.Close();
            dynamic jsonData = JsonConvert.DeserializeObject(responseString);
            uploadUrls[bucketId] = jsonData.uploadUrl;
            uploadAuthToken = jsonData.authorizationToken;
            return uploadUrls[bucketId];
        }
public string b2_get_upload_url ( string bucketId ) { if ( ! checkStringParamsNotEmpty ( new string [ ] { bucketId } ) || ! authorized ) { return " " ; } if ( uploadUrls . ContainsKey ( bucketId ) ) { return uploadUrls [ bucketId ] ; } HttpWebRequest webRequest = ( HttpWebRequest ) WebRequest . Create ( apiUrl + " " ) ; string body = " \" \" \" " + bucketId + " \" " ; var data = Encoding . UTF8 . GetBytes ( body ) ; webRequest . Method = " " ; webRequest . Headers . Add ( " " , authorizationToken ) ; webRequest . ContentType = " " ; webRequest . ContentLength = data . Length ; using ( var stream = webRequest . GetRequestStream ( ) ) { stream . Write ( data , 0 , data . Length ) ; stream . Close ( ) ; } WebResponse response = ( HttpWebResponse ) webRequest . GetResponse ( ) ; var responseString = new StreamReader ( response . GetResponseStream ( ) ) . ReadToEnd ( ) ; response . Close ( ) ; dynamic jsonData = JsonConvert . DeserializeObject ( responseString ) ; uploadUrls [ bucketId ] = jsonData . uploadUrl ; uploadAuthToken = jsonData . authorizationToken ; return uploadUrls [ bucketId ] ; }
Gets Upload Url for pushing files to a specific bucket.
Gets Upload Url for pushing files to a specific bucket .
string upload url
string upload url
bucketId
string
Id for bucket to get upload url for
Id for bucket to get upload url for