【发布时间】:2018-05-30 01:57:44
【问题描述】:
我正在构建一个体育网络应用程序,对于该应用程序,我需要每个 NBA 篮球运动员的缩略图。我编写了一个抓取图像路径的脚本(像这样的链接 - http://a.espncdn.com/combiner/i?img=/i/headshots/nba/players/full/3414.png&w=350&h=254),所以我可以访问所有图像,但我不确定 React 的最佳实践是在哪里保存这些类型的图像.我认为我的选择是:
- 将每个播放器的图像文件保存在应用程序目录中(保存其他图像的位置,我认为是我的应用程序的资产文件夹),然后将它们导入应用程序。
- 不要保存图像文件,而是在我的数据库中创建一个包含玩家 ID 和图像路径的表,并让我的应用使用这些路径来获取已经托管的图像。
- 基本上是 A 和 B。先保存图片文件,然后自己重新托管图片文件,并链接到这些新托管的图片。
这三个选择有意义吗?我觉得(3)是最好的选择,但也需要最多的工作。 (2) 似乎是最简单但最不可靠的,因为我不能相信已经托管的图像 url 将始终有效,并且 (1) 似乎不是最好的方法,因为它需要数百个 import 语句在我的应用程序来获取所有图像。
不是一个编码问题,但我认为这具有广泛的适用性,并希望这篇文章能坚持下去。对此的任何帮助或想法表示赞赏!
编辑:作为参考,下面是我的表格的样子:
> player.image.df
[,1] [,2]
[1,] "alex-abrines" "http://a.espncdn.com/combiner/i?img=/i/headshots/nba/players/full/2995702.png&w=350&h=254"
[2,] "quincy-acy" "http://a.espncdn.com/combiner/i?img=/i/headshots/nba/players/full/6576.png&w=350&h=254"
[3,] "steven-adams" "http://a.espncdn.com/combiner/i?img=/i/headshots/nba/players/full/2991235.png&w=350&h=254"
[4,] "bam-adebayo" "http://a.espncdn.com/combiner/i?img=/i/headshots/nba/players/full/4066261.png&w=350&h=254"
[5,] "arron-afflalo" "http://a.espncdn.com/combiner/i?img=/i/headshots/nba/players/full/3187.png&w=350&h=254"
[6,] "alexis-ajinca" "http://a.espncdn.com/combiner/i?img=/i/headshots/nba/players/full/3410.png&w=350&h=254"
[7,] "cole-aldrich" "http://a.espncdn.com/combiner/i?img=/i/headshots/nba/players/full/4267.png&w=350&h=254"
[8,] "lamarcus-aldridge" "http://a.espncdn.com/combiner/i?img=/i/headshots/nba/players/full/2983.png&w=350&h=254"
[9,] "jarrett-allen" "http://a.espncdn.com/combiner/i?img=/i/headshots/nba/players/full/4066328.png&w=350&h=254"
[10,] "kadeem-allen" "http://a.espncdn.com/combiner/i?img=/i/headshots/nba/players/full/3134880.png&w=350&h=254"
这些不是我的链接,我无法知道 ESPN 是否会更改这些链接,这就是为什么我认为 (3) 是最好的方法。但我不确定如何快速轻松地托管自己的图像。
【问题讨论】: