Akamai.NetStorage.NetStorage.Upload C# (CSharp) Method

Upload() public method

public Upload ( string path, FileInfo srcFile, bool indexZip = null ) : bool
path string
srcFile System.IO.FileInfo
indexZip bool
return bool
        public bool Upload(string path, FileInfo srcFile, bool? indexZip = null)
        {
            if (!srcFile.Exists) throw new FileNotFoundException("Src file is not accessible", srcFile.ToString());

            DateTime mTime = srcFile.LastWriteTime;
            byte[] checksum = null;
            Stream stream;
            using (stream = new BufferedStream(srcFile.OpenRead(), 1024*1024))
            {
                checksum = stream.ComputeHash(NetstorageCMSv35Signer.HashType.SHA256.Checksum);
            }

            stream = srcFile.OpenRead();
            long size = srcFile.Length;

            return this.Upload(path, stream, mTime, size, sha256Checksum: checksum, indexZip: indexZip);
        }

Same methods

NetStorage::Upload ( string path, Stream uploadFileStream, System.DateTime mTime = null, long size = null, byte md5Checksum = null, byte sha1Checksum = null, byte sha256Checksum = null, bool indexZip = null ) : bool

Usage Example

示例#1
0
        static void execute(string action, string user, string key, string netstorageURI,
                            string uploadfile, string outputfile, string target, string dst, bool indexZip)
        {
            if (action == null || netstorageURI == null || user == null || key == null)
            {
                help();
                return;
            }

            string[]   hostpath = netstorageURI.Split("/".ToCharArray(), 2);
            string     host     = hostpath[0];
            string     path     = hostpath[1];
            NetStorage ns       = new NetStorage(host, user, key);
            Stream     result   = null;
            bool       success  = true;

            switch (action)
            {
            case " delete":
            case "dir":
                result = ns.Dir(path);
                break;

            case "download":
                result = ns.Download(path);
                break;

            case "du":
                result = ns.DU(path);
                break;

            case "mkdir":
                success = ns.MkDir(path);
                break;

            case "mtime":
                success = ns.MTime(path);
                break;

            case "rename":
                if (dst == null)
                {
                    help();
                    return;
                }
                success = ns.Rename(path, dst);
                break;

            case "rmdir":
                success = ns.RmDir(path);
                break;

            case "stat":
                result = ns.Stat(path);
                break;

            case "symlink":
                if (target == null)
                {
                    help();
                    return;
                }
                success = ns.Symlink(path, target);
                break;

            case "upload":
                if (uploadfile == null)
                {
                    help();
                    return;
                }
                success = ns.Upload(path, new FileInfo(uploadfile), indexZip);
                break;

            default:
                help();
                return;
            }

            if (result != null)
            {
                Stream output = Console.OpenStandardOutput();
                if (outputfile != null)
                {
                    output = new FileInfo(outputfile).OpenWrite();
                }

                using (output)
                {
                    using (result)
                    {
                        byte[] buffer    = new byte[32 * 1024];
                        int    bytesRead = 0;

                        while ((bytesRead = result.Read(buffer, 0, buffer.Length)) != 0)
                        {
                            output.Write(buffer, 0, bytesRead);
                        }
                    }
                }
            }
            else if (success)
            {
                Console.Out.WriteLine("Success.");
            }
            else
            {
                Console.Error.WriteLine("Error.");
            }
        }
All Usage Examples Of Akamai.NetStorage.NetStorage::Upload