C
C#13mo ago
SylveonDeko

Best way to limit file size when downloading a url

So im adding a way to ahve custom images for xp but dont want to have people put in custom urls that have it download a file thats over 10gb lol. Best way to avoid this? And no im not limiting to discord file uploads unless absolutely necessary
6 Replies
Buddy
Buddy13mo ago
I'm not sure what you mean, are you downloading those images on your end? Or are users UPLOADING them to your server?
SylveonDeko
SylveonDekoOP13mo ago
correct
slapajimmy
slapajimmy13mo ago
is there some frontend sending this to a backend? Would like more context of the system
Buddy
Buddy13mo ago
Generally you would just grab the first few bytes of the data, check if it matches the magic bytes of for example a PNG https://en.m.wikipedia.org/wiki/List_of_file_signatures
List of file signatures
This is a list of file signatures, data used to identify or verify the content of a file. Such signatures are also known as magic numbers or Magic Bytes. Many file formats are not intended to be read as text. If such a file is accidentally viewed as a text file, its contents will be unintelligible. However, sometimes the file signature can be re...
Buddy
Buddy13mo ago
And then check the length of the data and if it is above a certain limit, give an error saying like file size is too large. If the magic bytes of a PNG does not match then you know it is not a valid PNG
SylveonDeko
SylveonDekoOP13mo ago
nope just a discord bot got it thx on another note what the fuck am i doing wrong here???
using Microsoft.EntityFrameworkCore.Migrations;

namespace Mewdeko.Database.Migrations.PostgreSQL;

public partial class AddXpImage : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "XpImgUrl",
table: "GuildConfigs",
type: "text",
nullable: true);
}
}
using Microsoft.EntityFrameworkCore.Migrations;

namespace Mewdeko.Database.Migrations.PostgreSQL;

public partial class AddXpImage : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "XpImgUrl",
table: "GuildConfigs",
type: "text",
nullable: true);
}
}
// <auto-generated />

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;

namespace Mewdeko.Database.Migrations.PostgreSql
{
[DbContext(typeof(MewdekoPostgresContext))]
[Migration("AddXpTemplateStuff")]
partial class AddXpImage
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
// required for reasons
}
}
}
// <auto-generated />

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;

namespace Mewdeko.Database.Migrations.PostgreSql
{
[DbContext(typeof(MewdekoPostgresContext))]
[Migration("AddXpTemplateStuff")]
partial class AddXpImage
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
// required for reasons
}
}
}
why is it telling me theres no method to override??? someone please help me hbefore i have a breakdown here CryHard
Want results from more Discord servers?
Add your server