コード例 #1
0
        // This was tricky had to copy link from synology
        // webapi/entry.cgi?api=SYNO.FileStation.Thumb&
        //  method=get&version=2&
        // SynoToken=itXJMhBSq7YL6&
        // path=%22%2Fphoto%2F2017%2FIMG_0285.JPG%22&
        // mt=1499625080


        public byte[] GetThumb(string path, ThumbnailSizeOption size = ThumbnailSizeOption.small,
                               ThumbnailRotateOptions rotate         = ThumbnailRotateOptions.none)
        {
            var request = new SynologyRestRequest();

            request.AddParameter("api", "SYNO.FileStation.Thumb");
            request.AddParameter("version", "2");
            request.AddParameter("method", "get");



            request.AddParameter("path", "\"" + path + "\"");
            request.AddParameter("size", size.ToString());
            request.AddParameter("rotate", (int)rotate);
            request.AddParameter("_sid", _session.sid);
            var config   = new AppSettingsClientConfig();
            var client   = new RestClient(config.ApiBaseAddressAndPathNoTrailingSlash + "/entry.cgi");
            var response = client.Execute(request);

            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new SynologyClientException("The request failed with " + response.StatusCode);
            }
            return(response.RawBytes);
        }
コード例 #2
0
        public RawSynologyResponse Upload(FileInfo fileName, string destinationFilePath, bool createParents = true,
                                          bool?overwrite = true)
        {
            var request = new SynologyRestRequest(Method.POST);

            request.AddParameter("_sid", _session.sid, ParameterType.QueryString);
            request.AddParameter("api", "SYNO.FileStation.Upload", ParameterType.QueryString);
            request.AddParameter("version", "2", ParameterType.QueryString);
            request.AddParameter("method", "upload", ParameterType.QueryString);
            request.AddParameter("path", destinationFilePath);
            request.AddParameter("create_parents", createParents);
            request.AddParameter("mtime", DateTimeExtender.GetUnixTimeFromDate(fileName.LastWriteTimeUtc).ToString());
            request.AddParameter("crtime", DateTimeExtender.GetUnixTimeFromDate(fileName.CreationTimeUtc).ToString());
            request.AddParameter("atime", DateTimeExtender.GetUnixTimeFromDate(fileName.LastAccessTimeUtc).ToString());
            request.AddParameter("overwrite", overwrite);

            request.AddFile(fileName.Name, fileName.FullName);

            var config = new AppSettingsClientConfig();
            var client = new RestClient(config.ApiBaseAddressAndPathNoTrailingSlash + "/entry.cgi");

            var response = client.Execute <RawSynologyResponse>(request);

            return(response.Data);
        }
コード例 #3
0
        public byte[] Download(string filePath, DownloadMode mode = DownloadMode.download)
        {
            var request = new SynologyRestRequest();

            request.AddParameter("api", "SYNO.FileStation.Download");
            request.AddParameter("version", "1");
            request.AddParameter("method", "download");
            request.AddParameter("path", filePath);
            request.AddParameter("mode", mode);
            request.AddParameter("_sid", _session.sid);
            var config   = new AppSettingsClientConfig();
            var client   = new RestClient(config.ApiBaseAddressAndPathNoTrailingSlash + "/entry.cgi");
            var response = client.Execute(request);

            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new SynologyClientException("Errored with http status code " + response.StatusCode);
            }
            return(response.RawBytes);
        }