如何将照片从画廊保存到Xamarin中Windows服务器上的共享文件夹

时间:2019-09-02 06:44:22

标签: c# xamarin

我正在尝试将Android Gallery中的图像保存到Windows服务器上的共享文件夹中。安装了NuGet SharpCifs.Std软件包后,我尝试使用 CopyTo 方法保存图像,但是在我所知的路径正确时会出现错误。

这是错误

https://ibb.co/2v0BrqD

代码段...

using SharpCifs.Smb;
...
...
var windowsAuth = new NtlmPasswordAuthentication("mydomain.local", "user", "password");
var source = new SmbFile(photoFile);
var dest = new SmbFile(photosPath, windowsAuth);
source.CopyTo(dest);

在调试模式下,变量的值为:

源= file:///storage/emulated/0/Android/data/com.salicru/files/Pictures/temp/IMG_20190828_101004_88.jpg

目的地= file:// srvdoc / compartit / fotos equips / M3 / 6A0BW000001 /

我在做什么错了?

1 个答案:

答案 0 :(得分:0)

我必须创建一个称为ConvertMediaFileToByteArray的方法,用于将照片流转换为字节[]。

var result = await pca.AcquireTokenInteractive(_scopes)
                        .WithPrompt(Prompt.ForceLogin)
                        .ExecuteAsync()

正在转接电话。

private byte[] ConvertMediaFileToByteArray(MediaFile file)
{
     using (var memoryStream = new MemoryStream())
     {
          file.GetStream().CopyTo(memoryStream);
          return memoryStream.ToArray();
     }
 }

然后,我没有使用CopyTo方法,而是使用CreateNewFile方法。

file = await CrossMedia.Current.PickPhotoAsync(new PickMediaOptions
{
    PhotoSize = PhotoSize.Small
});

if (file != null)
{
   imageSource = ImageSource.FromStream(() =>
   {
       var stream = file.GetStream();
       file.Dispose();
       return stream;
   });

   //Convert ImatgeStream to BYTE[]
   var imageToByte = ConvertMediaFileToByteArray(file);
}