PutObject() public method

public PutObject ( string bucketName, string key, Stream content, ObjectMetadata metadata, Action uploadProcessCallback = null, CancellationToken cancellationToken = null ) : Task
bucketName string
key string
content Stream
metadata ObjectMetadata
uploadProcessCallback Action
cancellationToken System.Threading.CancellationToken
return Task
示例#1
0
        public void OnFileChanged(object sender, FileSystemEventArgs e)
        {
            try
            {
                if (e.ChangeType != WatcherChangeTypes.Changed && e.ChangeType != WatcherChangeTypes.Created)
                {
                    return;
                }
                if (string.IsNullOrEmpty(Path.GetExtension(e.FullPath)))
                {
                    return;
                }

                var filePath = e.FullPath;
                var siteId   = _api.GetSiteIdByFilePath(e.FullPath);
                if (siteId <= 0)
                {
                    return;
                }
                var siteDirectoryPath = _api.GetSiteDirectoryPath(siteId);
                if (string.IsNullOrEmpty(siteDirectoryPath))
                {
                    return;
                }

                var isOss = _api.GetSiteOption(siteId, OptionIsOss) == true.ToString();
                if (!isOss)
                {
                    return;
                }

                var accessKeyId     = _api.GetSiteOption(siteId, OptionAccessKeyId);
                var accessKeySecret = _api.GetSiteOption(siteId, OptionAccessKeySecret);
                var bucketName      = _api.GetSiteOption(siteId, OptionBucketName);
                var bucketEndPoint  = _api.GetSiteOption(siteId, OptionBucketEndPoint);
                var bucketPath      = _api.GetSiteOption(siteId, OptionBucketPath);
                var key             = (bucketPath + GetRelativePath(filePath, siteDirectoryPath)).Trim('/');

                if (string.IsNullOrEmpty(accessKeyId) || string.IsNullOrEmpty(accessKeySecret) ||
                    string.IsNullOrEmpty(bucketName) || string.IsNullOrEmpty(bucketEndPoint) ||
                    string.IsNullOrEmpty(key))
                {
                    return;
                }

                var client = new OssClient(bucketEndPoint, accessKeyId, accessKeySecret);
                client.PutObject(bucketName, key, filePath);
            }
            catch (Exception ex)
            {
                _api.AddErrorLog(ex);
            }
        }
示例#2
0
        static async void PutObject()
        {
            try
            {
                OssClient  temp = new OssClient("v12bbAtA0rnTw0Wt", "Gz3OBVL4QHIWBBh5rD0kg1f9F4FnZU");
                FileStream fs   = new FileStream(@"C:\Users\zhonglei\Desktop\SLM2.m", FileMode.Open);
                // MemoryStream s = new MemoryStream();
                ObjectMetadata oMetaData = new ObjectMetadata();
                await temp.PutObject("devdoc2", "5/1.txt", fs, oMetaData, null, tokenSource.Token);

                fs.Dispose();
            }
            catch (Exception ex)
            {
            }
        }
示例#3
0
        static async void PutObject()
        {
            try
            {
                OssClient temp = new OssClient("v12bbAtA0rnTw0Wt", "Gz3OBVL4QHIWBBh5rD0kg1f9F4FnZU");
                FileStream fs = new FileStream(@"C:\Users\zhonglei\Desktop\SLM2.m", FileMode.Open);
               // MemoryStream s = new MemoryStream();
                ObjectMetadata oMetaData = new ObjectMetadata();
                await temp.PutObject("devdoc2", "5/1.txt", fs, oMetaData, null, tokenSource.Token);
                fs.Dispose();
            }
            catch(Exception ex)
            {

            }
        }