简体   繁体   English

将mp4文件转换为字节数组和字符串

[英]Convert mp4 file to byte array and string

I working on project to upload files into firebase real-time database using firesharp in WinForm c#.我在 WinForm c# 中使用 firesharp 将文件上传到 firebase 实时数据库。

I searched a lot to understand how to do this.我搜索了很多以了解如何执行此操作。

I know about the option to write File.ReadAllBytes(), but I want to run the app on weak PC, with 4 GB ram, and he is very slow.我知道编写 File.ReadAllBytes() 的选项,但我想在性能较差的 PC 上运行该应用程序,内存为 4 GB,而且速度很慢。 I succeeded to upload an image, it's work good.我成功上传了一张图片,效果很好。 I find something about Stram option, but I don't know how to do it with converting to String.我找到了一些关于 Stram 选项的信息,但我不知道如何转换为字符串。

Sorry about my English.对不起我的英语。

You can convert the file to binary, and the binary can be saved as arrays and strings.您可以将文件转换为二进制,二进制可以保存为 arrays 和字符串。

//Read file to byte array

FileStream stream = File.OpenRead(@"c:\path\to\your\file\here.txt");
byte[] fileBytes= new byte[stream.Length];

stream.Read(fileBytes, 0, fileBytes.Length);
stream.Close();
//Begins the process of writing the byte array back to a file

using (Stream file = File.OpenWrite(@"c:\path\to\your\file\here.txt"))
{
   file.Write(fileBytes, 0, fileBytes.Length);
}

https://www.codeproject.com/Questions/636646/Csharp-file-to-Byte-Array-and-Byte-Array-to-File https://www.codeproject.com/Questions/636646/Csharp-file-to-Byte-Array-and-Byte-Array-to-File

FileStream st = new FileStream(@"C:\2.jpg", FileMode.Open); 
            byte[] buffer = new byte[st.Length]; 
            st.Read(buffer, 0, (int)st.Length); 
            st.Close(); 
            Console.ReadLine(); 

https://social.msdn.microsoft.com/Forums/en-US/648bd8b2-74ec-4054-9c68-68190b600971/how-to-convert-a-file-to-binary?forum=csharplanguage https://social.msdn.microsoft.com/Forums/en-US/648bd8b2-74ec-4054-9c68-68190b600971/how-to-convert-a-file-to-binary?forum=csharplanguage

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将字节切片转换为字符串 - Convert slice of byte into string 使用 AWS media convert 自动转换所有现有的 s3.mp4 文件 - Auto convert all existing s3 .mp4 files using AWS media convert 字节数组到字符串转换不一致 - Byte Array To String Conversion Inconsistency Golang:将自定义类型(别名 [32]byte)转换为字符串 - Golang: convert custom type (alias to [32]byte) to string 保存和下载 .mp4 文件的高 Google Firebase 存储成本? - High Google Firebase Storage Cost for saving and downloading .mp4 files? 在 Presto Athena 中将字符串转换为数组 - Convert String to Array in Presto Athena Flutter - 将 mp4 上传到 Firebase 存储 - 仅捕获音频 - Flutter - uploading mp4 to Firebase storage - only audio captured 如何仅将视频 (mp4) 发送到 stream 到 kinesis-video-stream - How to send only video (mp4) to stream to kinesis-video-stream 如何在一个文件夹中一次翻译多个.mp4 视频标题? - How can I translate multiple .mp4 video Titles at once in a folder? mp4 视频无法在 ios 移动设备或 firefox 上播放,但在 chrome 和 safari 上可以正常播放 - mp4 video not playing on ios mobile or firefox, but work fine in chrome and safari
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM