FileSync/FileSync/B2SDK.cs
/// <summary>
/// Downloads a file from b2 given a fileName and Bucket to download from
/// </summary>
/// <param name="fileName"> Name of file to download</param>
/// <param name="bucketName"> Name of bucket that file is stored in</param>
/// <returns> Byte array of downloaded file. Returns null if fileName/bucketname combo are invalid.</returns>
Downloads a file from b2 given a fileName and Bucket to download from
Downloads a file from b2 given a fileName and Bucket to download from
public byte[] b2_download_file_by_name(string fileName, string bucketName)
        {
            if (!checkStringParamsNotEmpty(new string[] { fileName, bucketName }) || !authorized)
            {
                return null;
            }
            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(String.Format("{0}/file/{1}/{2}", downloadURL, bucketName, fileName));
            webRequest.Method = "GET";
            webRequest.Headers.Add("Authorization", authorizationToken);
            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_name ( string fileName , string bucketName ) { if ( ! checkStringParamsNotEmpty ( new string [ ] { fileName , bucketName } ) || ! authorized ) { return null ; } HttpWebRequest webRequest = ( HttpWebRequest ) WebRequest . Create ( String . Format ( " " , downloadURL , bucketName , fileName ) ) ; webRequest . Method = " " ; webRequest . Headers . Add ( " " , authorizationToken ) ; 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 fileName and Bucket to download from
Downloads a file from b2 given a fileName and Bucket to download from
Byte array of downloaded file. Returns null if fileName/bucketname combo are invalid.
Byte array of downloaded file . Returns null if fileName / bucketname combo are invalid .
fileName
string
Name of file to download
Name of file to download
bucketName
string
Name of bucket that file is stored in
Name of bucket that file is stored in