[英]How to save photos from gallery to shared folder on a windows server in xamarin
I am trying to save an image from the Android gallery to a shared folder on a windows server. 我正在尝试将图像从Android画廊保存到Windows服务器上的共享文件夹中。 With the NuGet SharpCifs.Std package installed, I try to use the CopyTo method to save the image but it gives an error when the path is correct to my knowledge.
安装了NuGet SharpCifs.Std程序包后,我尝试使用CopyTo方法保存图像,但是在我所知路径正确时,它将给出错误消息。
This is the error 这是错误
Piece of code ... 一段代码...
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);
In debug mode, the value of variables are: 在调试模式下,变量的值为:
source = file:///storage/emulated/0/Android/data/com.salicru/files/Pictures/temp/IMG_20190828_101004_88.jpg 来源= file:///storage/emulated/0/Android/data/com.salicru/files/Pictures/temp/IMG_20190828_101004_88.jpg
dest = file://srvdoc/compartit/fotos equips/M3/6A0BW000001/ dest = file:// srvdoc / compartit / fotos equips / M3 / 6A0BW000001 /
What am I doing wrong? 我究竟做错了什么?
I had to create a method that I called ConvertMediaFileToByteArray for the conversion of the photo stream to a byte[]. 我必须创建一个称为ConvertMediaFileToByteArray的方法,用于将照片流转换为byte []。
private byte[] ConvertMediaFileToByteArray(MediaFile file)
{
using (var memoryStream = new MemoryStream())
{
file.GetStream().CopyTo(memoryStream);
return memoryStream.ToArray();
}
}
Converting call. 转换通话。
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);
}
Then, instead of using CopyTo method i used CreateNewFile method. 然后,不是使用CopyTo方法,而是使用CreateNewFile方法。
var windowsAuth = new NtlmPasswordAuthentication("domain", "admin", "password");
var dest = new SmbFile(photosPath + imageName, windowsAuth);
dest.CreateNewFile();
var writeStream = dest.GetOutputStream();
writeStream.Write(imageToByte);
writeStream.Dispose();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.