在服务器数据库中下载和存储图像
因此,目前,我的网站正在从我的服务器上加载一个JSON文件,寻找所需的数据,然后在屏幕上显示并显示并下载并显示与该信息有关的图像中的公共API。我想知道如何将API下载的图像存储到我自己的服务器数据库中将其存储在我的服务器数据库中?
下面的代码是一个示例,当加载站点时,它将从JSON中取出随机卡,并与图像一起显示其信息。我想从API下载图像,将其存储在我的服务器数据库中,然后在下载之前检查该图像以最少将API调用减少。
function RandomCard() {
const RC = Math.floor(Math.random() * cardAPIListings.data.length);
var cardShowcase = document.getElementById("randomcardshowcase");
var randomCardImage = document.getElementById('randomImage');
switch (cardAPIListings.data[RC].type) {
case "Spell Card":
case "Trap Card":
cardShowcase.innerHTML = '\"' +cardAPIListings.data[RC].name + '\"' + '<br><br>' + '[' +
cardAPIListings.data[RC].race + ' / ' + cardAPIListings.data[RC].type + ']' + '<br>' +
'Attri: ' + cardAPIListings.data[RC].attribute + '<br><br>' + 'Effect: ' + '<br>' +
cardAPIListings.data[RC].desc;
randomCardImage.src = cardAPIListings.data[RC].card_images[0].image_url;
break;
编辑: 我正在使用的公共API说:
[卡片图像 直接从服务器而不是Google Cloud存储库中拉出我们的卡片图像的用户将立即列入黑名单。
可以从我们的Google Cloud Server中提取卡片映像,但请仅拉一个图像 ,然后将其存储在本地(我假设这意味着将其存储在您自己的服务器/API数据库中)
。 如果我们发现您每秒拉出很高的图像,那么您的IP将被黑名单和封锁。],
所以我需要一种将图像存储在我自己的位置的方法,因为它们是从我自己的位置下载的公共API,所以我不会被黑名单。
So currently my website is loading an JSON File from my server, looking for the data it needs and then showing it up on the screen as well as downloading and showing an image related to that info from a public API. I was wondering how would I go about storing the API downloaded image to my own servers database so before every image fetch it would check for the image in my server and if it doesn't exist, it would go to the public API and download and store it in my servers database?
This code below is a sample, when the site is loaded it pulls a random card from the JSON and displays its info along with the image. I want to download the image from the api, store it in my servers database and then check for said image before downloading as to reduce API calls to a minimum.
function RandomCard() {
const RC = Math.floor(Math.random() * cardAPIListings.data.length);
var cardShowcase = document.getElementById("randomcardshowcase");
var randomCardImage = document.getElementById('randomImage');
switch (cardAPIListings.data[RC].type) {
case "Spell Card":
case "Trap Card":
cardShowcase.innerHTML = '\"' +cardAPIListings.data[RC].name + '\"' + '<br><br>' + '[' +
cardAPIListings.data[RC].race + ' / ' + cardAPIListings.data[RC].type + ']' + '<br>' +
'Attri: ' + cardAPIListings.data[RC].attribute + '<br><br>' + 'Effect: ' + '<br>' +
cardAPIListings.data[RC].desc;
randomCardImage.src = cardAPIListings.data[RC].card_images[0].image_url;
break;
Edit:
The PUBLIC API that I'm using says this:
[ Card Images
Users who pull our card images directly from our server instead of our google cloud repository will be immediately blacklisted.
Card images can be pulled from our Google Cloud server but please only pull an image once and then store it locally(I Assume this means Store it in your Own Server/API Database)
.
If we find you are pulling a very high volume of images per second then your IP will be blacklisted and blocked.]
So I need a way to store the images in my own location as they are being downloaded from the Public API so I Dont get blacklisted.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除非我误解了您的问题,否则仅将图像和其他二进制数据存储到文件系统中。
没有理由使用大二进制数据负担数据库。仅在数据库中存储文件链接(或URL)。
Unless I'm misunderstanding your question, only store images and other binary data to the file system.
No reason to burden database with big binary data. Only store file link (or URL) in the database.