protected override object UpdateAttachment(IDbDataSource host, IFieldUpload upload, IFieldValueAccessor accessor, string oldPath, string newPath) { if (UseAliyunUploadMode) { FileConfig temp = FileConfig.ReadFromJson(newPath); string json = accessor.GetValue(upload.ContentField); FileConfig config = FileConfig.ReadFromJson(json); accessor.SetValue(upload.ServerPathField, config.AccessUrl); temp.RemoveTo(config); } else { string json = accessor.GetValue(upload.ContentField); FileConfig config = FileConfig.ReadFromJson(json); accessor.SetValue(upload.ServerPathField, config.AccessUrl); string originFileName = accessor.GetValue(upload.FileNameField); config.UploadFile(newPath, originFileName); } return(null); }
protected override object DeleteAttachment(IDbDataSource host, IFieldUpload upload, IFieldValueAccessor accessor, string path) { try { var json = accessor.GetValue(upload.ContentField); accessor.SetValue(upload.ContentField, DBNull.Value); FileConfig config = FileConfig.ReadFromJson(json); config.Delete(); } catch { } return(null); }
protected override object InsertAttachment(IDbDataSource host, IFieldUpload upload, IFieldValueAccessor accessor, string path) { if (UseAliyunUploadMode) { FileConfig temp = FileConfig.ReadFromJson(path); FileConfig config = new FileConfig(BucketName, temp.ObjectName); accessor.SetValue(upload.ServerPathField, config.AccessUrl); accessor.SetValue(upload.ContentField, config.ToString()); temp.RemoveTo(config); } else { string fileName = Path.GetFileNameWithoutExtension(path); FileConfig config = new FileConfig(BucketName, fileName); accessor.SetValue(upload.ServerPathField, config.AccessUrl); accessor.SetValue(upload.ContentField, config.ToString()); string originFileName = accessor.GetValue(upload.FileNameField); config.UploadFile(path, originFileName); } return(null); }