public async Task <ImageUploadResult> UploadAsync(ImageUploadParameters parameters) { try { var cloudinaryUploadParams = new ImageUploadParams { File = new FileDescription($@"{parameters.ImageBas64Uri}") }; var cloudinaryUploadResult = await _cloudinary.UploadAsync(cloudinaryUploadParams); return(new ImageUploadResult { IsSuccessful = true, PublicId = cloudinaryUploadResult.PublicId, Uri = cloudinaryUploadResult.SecureUri }); } catch (Exception e) { // log Console.WriteLine(e); return(new ImageUploadResult { IsSuccessful = false }); } }
public ServiceProcess Execute(string directory, string folderUri, string schemaUri) { if (string.IsNullOrEmpty(directory)) { throw new ArgumentNullException("directory"); } if (string.IsNullOrEmpty(folderUri)) { throw new ArgumentNullException("folderUri"); } if (string.IsNullOrEmpty(schemaUri)) { throw new ArgumentNullException("schemaUri"); } ImageUploadParameters arguments = new ImageUploadParameters { Directory = directory, FolderUri = folderUri, SchemaUri = schemaUri }; return ExecuteAsync(arguments); }
public ServiceProcess Execute(string directory, string folderUri, string schemaUri) { if (string.IsNullOrEmpty(directory)) { throw new ArgumentNullException("directory"); } if (string.IsNullOrEmpty(folderUri)) { throw new ArgumentNullException("folderUri"); } if (string.IsNullOrEmpty(schemaUri)) { throw new ArgumentNullException("schemaUri"); } ImageUploadParameters arguments = new ImageUploadParameters { Directory = directory, FolderUri = folderUri, SchemaUri = schemaUri }; return(ExecuteAsync(arguments)); }
public override void Process(ServiceProcess process, object arguments) { ImageUploadParameters parameters = (ImageUploadParameters)arguments; try { string directory = parameters.Directory; if (!Directory.Exists(directory)) { process.Failed = true; process.Complete(string.Format(CultureInfo.InvariantCulture, "Directory '{0}' does not exist. No images were uploaded!", directory)); return; } string[] files = Directory.GetFiles(directory); int i = 0; _client = PowerTools.Common.CoreService.Client.GetCoreService(); //Get all component titles in the target folder _componentTitles = getAllComponentTitles(parameters.FolderUri); foreach (string file in files) { process.SetStatus("Importing image: " + Path.GetFileName(file)); process.SetCompletePercentage(++i * 100 / files.Length); FileInfo fileInfo = new FileInfo(file); if (fileInfo.Exists) { string mmType = GetMultiMediaType(fileInfo.Extension); if (mmType != null) { BinaryContentData bcd = new BinaryContentData { UploadFromFile = file, MultimediaType = new LinkToMultimediaTypeData { IdRef = mmType }, Filename = file, IsExternal = false }; ComponentData compData = new ComponentData { LocationInfo = new LocationInfo { OrganizationalItem = new LinkToOrganizationalItemData { IdRef = parameters.FolderUri //Organizational item }, }, ComponentType = ComponentType.Multimedia, Title = MakeValidFileName(fileInfo.Name), Schema = new LinkToSchemaData { IdRef = parameters.SchemaUri //schemaData.IdRef }, IsBasedOnMandatorySchema = false, IsBasedOnTridionWebSchema = true, ApprovalStatus = new LinkToApprovalStatusData { IdRef = "tcm:0-0-0" }, Id = "tcm:0-0-0", BinaryContent = bcd }; ComponentData comp = (ComponentData)_client.Create(compData, new ReadOptions()); } } } process.Complete(); } finally { if (_client != null) { _client.Close(); } } }