本文介绍了Xamarin表单-以流形式打开文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个非常简单的问题,但是当我们谈论流时,我总是感到困惑.我正在尝试在Android部分的Xamarin Forms项目中打开文件.我有一个Java.IO.File,我希望将其转换为流,以便能够使用该简单函数将其发送到Azure Blob存储:

This might be a very simple question but I'm always confused when we're talking about streams.I'm trying to open a file in my Xamarin Forms project in the Android part of it.I have a Java.IO.File which I would like to convert into a stream to be able to send it to an Azure Blob Storage with that simple function :

        public async Task<string> UploadFileAsync(Stream stream)
        {
        await this.container.CreateIfNotExistsAsync();

        var name = "Photo_" + Guid.NewGuid().ToString();
        var fileBlob = container.GetBlockBlobReference(name);
        await fileBlob.UploadFromStreamAsync(stream);

        return name;
        }

但是,我似乎无法将Android部分中的StreamReader与StreamReader或OutputStreamWriter.有人遇到过同样的问题吗?谢谢!

However, I can't seem to be able to use StreamReader from the Android part withStreamReader or OutputStreamWriter.Did anyone encounter the same issue ?Thank you !

推荐答案

您应该能够只使用System.IO中的StreamReader类.示例代码可能如下所示:

You should be able to just use the StreamReader class from System.IO. Sample code could look something like this:

FileStream fs = new FileStream("photo.jpg", FileMode.Open, FileAccess.Read);

StreamReader r = new StreamReader(fs);

完成操作后,请不要忘记处理它们.

Don't forget to dispose them after you are done.

有关如何上传到Azure容器的更多详细信息,请查看 Xamarin文档.

For more detail on how to upload to Azure containers, check out the Xamarin documentation.

这篇关于Xamarin表单-以流形式打开文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 10:14