Ejemplo n.º 1
0
        static string UpsertAsset(Google.Apis.Drive.v3.Data.File file, bool update, Stream stream)
        {
            string            externalId = file.Name;
            string            message    = null;
            FileContentSource fcs        = new FileContentSource(stream, externalId, file.MimeType);
            AssetModel        result;
            var emptyDescriptions = new List <AssetDescription>
            {
                new AssetDescription {
                    Description = "", Language = LanguageIdentifier.ById(new Guid("00000000-0000-0000-0000-000000000000"))
                }
            };

            try
            {
                var           fileTask = clientCM.UploadFileAsync(fcs);
                FileReference fr       = fileTask.GetAwaiter().GetResult();

                IEnumerable <AssetDescription> descriptions = new List <AssetDescription>();
                AssetUpsertModel model = new AssetUpsertModel
                {
                    FileReference = fr,
                    Descriptions  = emptyDescriptions
                };
                var createTask = clientCM.CreateAssetAsync(model);
                result = createTask.GetAwaiter().GetResult();
            }
            catch (Exception ex)
            {
                message = ex.Message;
            }

            return(message);
        }
Ejemplo n.º 2
0
        //private readonly DeliveryClient _deliveryClient;

        public async Task <string> CreateAssetAsync()
        {
            // Defines the description of an asset
            var assetDescription = new AssetDescription
            {
                Description = "Description of the asset in the default Language",
                Language    = LanguageIdentifier.DEFAULT_LANGUAGE
            };

            IEnumerable <AssetDescription> descriptions = new [] { assetDescription };

            const string filePath    = @"C:\Users\mattn\projects\KenticoCloudImport\KenticoCloudImport\Images\KenticoCloudLogo.jpg";
            const string contentType = "image/jpg";

            // Uploads the file and links it to a new asset
            var response = await _managementClient.CreateAssetAsync(new FileContentSource(filePath, contentType), descriptions);

            return(response.ExternalId);
        }