FileSync/FileSync/B2SDK.cs
/// <summary>
/// Downloads a file from b2 given a fileId
/// </summary>
/// <param name="fileId"> ID of file to download</param>
/// <returns>Byte array of download data. Returns null if invalid fileId</returns>
Downloads a file from b2 given a fileId
Downloads a file from b2 given a fileId
public byte[] b2_download_file_by_id(string fileId)
        {
            if (!checkStringParamsNotEmpty(new string[] { fileId }) || !authorized)
            {
                return null;
            }
            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(downloadURL + "/b2api/v1/b2_download_file_by_id");
            string body = "{\"fileId\":\"" + fileId + "\"}";
            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();
            Stream responseStream = response.GetResponseStream();
            byte[] fileBytes;
            using (BinaryReader br = new BinaryReader(responseStream))
            {
                fileBytes = br.ReadBytes(500000);
                br.Close();
            }
            responseStream.Close();
            response.Close();
            return fileBytes;
        }
public byte [ ] b2_download_file_by_id ( string fileId ) { if ( ! checkStringParamsNotEmpty ( new string [ ] { fileId } ) || ! authorized ) { return null ; } HttpWebRequest webRequest = ( HttpWebRequest ) WebRequest . Create ( downloadURL + " " ) ; string body = " \" \" \" " + fileId + " \" " ; 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 ( ) ; Stream responseStream = response . GetResponseStream ( ) ; byte [ ] fileBytes ; using ( BinaryReader br = new BinaryReader ( responseStream ) ) { fileBytes = br . ReadBytes ( 500000 ) ; br . Close ( ) ; } responseStream . Close ( ) ; response . Close ( ) ; return fileBytes ; }
Downloads a file from b2 given a fileId
Downloads a file from b2 given a fileId
Byte array of download data. Returns null if invalid fileId
Byte array of download data . Returns null if invalid fileId
fileId
string
ID of file to download
ID of file to download