简体   繁体   English

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

[英]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 这是错误

https://ibb.co/2v0BrqD

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.

相关问题 Xamarin中如何正确保存文件到共享文件夹? - How to properly save a file in a shared folder in Xamarin? 如何使用 xamarin 将照片保存在 android 的图库文件夹中 - how to save photo in gallery folder in android using xamarin 如何在 xamarin 表单(android)上显示共享文件夹中的图像? - How to show image from shared folder on xamarin forms(android)? 如何以 xamarin 形式将视频保存到图库 - how to save videos to the gallery in xamarin forms 如何使用Windows服务将文件复制到共享文件夹(该共享文件夹在服务器上)? - How could i do to copy a file to a shared folder ( that shared folder is on server ) by using Windows service? Xamarin 显示来自网络共享文件夹的图像 - Xamarin display an image from a network shared folder 如何将从url(服务器)下载的图像保存到Windows应用商店中的本地文件夹 - how to save image downloaded from url(server) to local folder in windows store app 如何从 Xamarin Forms 中的图库中 select 多张图片并保存到所需的文件路径? - How to select multiple images from gallery in Xamarin Forms and save to desired file path? 如何从共享文件夹或另一台服务器复制和粘贴文件? - How to copy and paste the files from shared folder or from another server? 将图像从图像框保存到 Xamarin Forms 中的图库 - Save image from an image box to gallery in Xamarin Forms
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM