在Flutter中发送和接收文件

huangapple go评论83阅读模式
英文:

Sending and receiving files in Flutter

问题

我需要一种方法,让用户可以将存储在Flutter应用中的一些信息发送给其他用户,并让接收到该信息的用户在其应用中存储它。我可以通过消息传递以JSON文件的形式发送这些信息,但如果有更好的方法,我可以使用它。我该如何做,哪种选项最佳?

英文:

I need a way to let users send to other users some information stored in a Flutter app, and let the user that received that information store it in his app. I can send this info in a json file trough a messaging, but if there is a better way I can use it. How can I do this, and what's the best option?

答案1

得分: 1

你可以使用 share_plus 包通过电子邮件、WhatsApp、Telegram、云端驱动等方式来“分享”文件。该包使用平台的分享对话框。

要构建要分享的文件,你可以使用不同的包。例如,如果你想通过 Excel 表格分享信息,你可以使用 excel 包。

你可以在 pub.dev 上找到有关这些包的更多信息:

https://pub.dev/packages/share_plus

https://pub.dev/packages/excel

英文:

You can use the share_plus package to "share" files via email, whatsapp, telegram, drive, etc. The package uses the platform's sharing dialog.

To build the file you are going to share, you can use a different package. For example if you want to share the information through an excel sheet you can use excel package.

You can find more information about packages in pub.dev:

https://pub.dev/packages/share_plus

https://pub.dev/packages/excel

答案2

得分: 0

  1. HTTP请求:您可以将文件作为HTTP请求的一部分提交到服务器,然后服务器将文件交付给请求它的人。接收文件的人可以随后下载并保存在他们的应用程序中。在Flutter中,使用一些库(如httpdio)可以更轻松地进行HTTP查询。

  2. 蓝牙:您可以使用蓝牙直接将文件传输到另一用户的设备上。Flutter提供了一个名为flutter_blue的蓝牙插件,可用于发送和接收文件。

  3. 云存储:您可以通过将文件上传到诸如Google Drive或Dropbox之类的云存储服务来与接收用户共享文件。接收文件的用户随后可以从云存储服务下载内容并放入他们的应用程序中。有各种Flutter插件可用于与云存储提供程序进行交互,例如用于Google Drive的googleapis和用于Dropbox的dropbox_api

总结一下:如果您需要传输大文件或希望在没有互联网连接的情况下传输文件,蓝牙可能是最佳选择。如果您想要一个更可靠和可扩展的解决方案,使用云存储可能是更好的选择。

英文:

There are several ways:

1. HTTP requests: You can submit the file to a server as a part of an HTTP request, and the server will then deliver the file to the person who requested it. The person who will be receiving the file may then download it and save it to their app. Making HTTP queries is made easier by a number of libraries in Flutter, including http and dio.

2. Bluetooth: You may transfer the file directly to another user's device using Bluetooth. Flutter features a Bluetooth plugin named flutter_blue that you may use to send and receive files.

3. Cloud storage: You may share the file with the recipient user by uploading it to a cloud storage service like Google Drive or Dropbox. The recipient user may then download the content from the cloud storage service and put it in their app. There are various Flutter plugins available for interacting with cloud storage providers, such as googleapis for Google Drive and dropbox_api for Dropbox.


To summarize: Bluetooth may be the best choice if you need to communicate huge files or wish to transfer files without an internet connection. Using cloud storage could be a better option if you want a solution that is more dependable and expandable.

huangapple
  • 本文由 发表于 2023年3月8日 19:11:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/75672259.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定