makes cli upload of an image work
This commit is contained in:
parent
3b2384d82f
commit
b30fd4ad2a
@ -1,4 +1,5 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Piwigo.Client.Images;
|
||||||
|
|
||||||
namespace Piwigo.Client.Cli;
|
namespace Piwigo.Client.Cli;
|
||||||
|
|
||||||
@ -10,10 +11,21 @@ internal static class UploadHandler
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var imageToUpload = new FileInfo(options.ImagePath);
|
||||||
|
var md5Sum = await imageToUpload.CalculateMd5SumAsync();
|
||||||
|
|
||||||
logger.LogInformation(EventIds.Upload, "Uploading {ImagePath}", options.ImagePath);
|
logger.LogInformation(EventIds.Upload, "Uploading {ImagePath}", options.ImagePath);
|
||||||
var client = PiwigoClient.CreateClient(options.ServerUrl, options.UserName, options.Password, loggerFactory);
|
var client = PiwigoClient.CreateClient(options.ServerUrl, options.UserName, options.Password, loggerFactory);
|
||||||
var result = await client.UploadImageAsync(new FileInfo(options.ImagePath));
|
await client.Session.LoginAsync();
|
||||||
|
|
||||||
|
var imageUpload = new ImageUpload(md5Sum)
|
||||||
|
{
|
||||||
|
Albums = options.AlbumId.HasValue ? new List<(int AlbumId, int? Rank)> { new(options.AlbumId.Value, null) } : null
|
||||||
|
};
|
||||||
|
|
||||||
|
var result = await client.UploadImageAsync(imageToUpload, imageUpload);
|
||||||
logger.LogInformation(EventIds.ActionSucceeded, "Uploaded {ImagePath} with new image id {ImageId}", options.ImagePath, result.ImageId);
|
logger.LogInformation(EventIds.ActionSucceeded, "Uploaded {ImagePath} with new image id {ImageId}", options.ImagePath, result.ImageId);
|
||||||
|
|
||||||
return EventIds.ActionSucceeded.Id;
|
return EventIds.ActionSucceeded.Id;
|
||||||
}
|
}
|
||||||
catch (PiwigoException ex)
|
catch (PiwigoException ex)
|
||||||
|
Loading…
Reference in New Issue
Block a user