public Stream GetFile(FileId id) { try { var obj = _OssClient.GetObject(_BucketName, id.ToString()); if (!obj.Metadata.UserMetadata.ContainsKey("Expires") || String.IsNullOrWhiteSpace(obj.Metadata.UserMetadata["Expires"])) return obj.Content; var expirationTime = obj.Metadata.UserMetadata["Expires"].To<DateTime>(); if (expirationTime > DateTime.Now) { return obj.Content; } else { Delete(id); return null; } } catch (ServiceException ex) { if(ex.ErrorCode == "NoSuchKey") { return null; } else { throw new Exception("aliyun error:" + ex.ErrorCode + ";message:" + ex.ToString()); } } }
public bool Exists(FileId id) { return _OssClient.DoesObjectExist(_BucketName, id.ToString()); }
public void Delete(FileId id) { _OssClient.DeleteObject(_BucketName, id.ToString()); }
public void CreateOrUpdate(FileId id, System.IO.Stream stream) { _OssClient.PutObject(_BucketName, id.ToString(), stream); }
public void CreateOrAppend(FileId id, System.IO.Stream stream) { _OssClient.AppendObject(new AppendObjectRequest(_BucketName, id.ToString()){ Content = stream }); }
public void Copy(FileId sourceId, FileId destId) { _OssClient.CopyObject(new CopyObjectRequest(_BucketName, sourceId.ToString(), _BucketName, destId.ToString())); }