Danbooru

File naming

Posted under General

Prior to early 2016 or so, the filenames were just the 32 digit hexadecimal MD5 hash plus the extension and the tags hadn't been added yet, so there were neither spaces nor underscores originally. That was quite some time ago though.

Until recently, clicking the "Download" button under "Options" produced a filename with spaces where there are now underscores. There are also now two underscores added at the beginning of the filename of every single image. I would really like if the change would be reverted.

I know how things used to be, and about a week ago, they changed. Yes, right-clicking on an image and clicking "Save Image As..." always produced filenames as they are now, with underscores. That's why I used the "Download" button under "Options", which produced filenames with spaces. I'm not lying here, surely someone else can back me up on this.

Maybe not lying, but you are definitely misremembering. I have images saved from Danbooru back in 2017 that use the same name styles as we have right now. I certainly didn't manually add all those underscores.

The code for the "Options" section hasn't changed since March.

Talulah said:

Maybe not lying, but you are definitely misremembering. I have images saved from Danbooru back in 2017 that use the same name styles as we have right now. I certainly didn't manually add all those underscores.

I'm NOT misremembering, I have downloaded from this site for years with spaces in the filenames.

The "Download" filename is the same as the "Save Image As..." filename. They're generated in the same way. I'm going to guess you have a third party script changing it. The only recent change is that images moved from being hosted on danbooru.donmai.us to cdn.donmai.us. That may have broken scripts if they expected images to be on danbooru.donmai.us.

Revisiting this a year later it seems the issue is that since images are now cross-domain there is a restriction on sending download filenames. Apparently browsers are supposed to accept the value of the a's download attribute if content-disposition header is set to attachment but it seems they are not doing that for cross-origin requests. I noticed this in a custom instance of Danbooru where the 'Download' filename is generated differently to the tagged file URL (same-origin) and it seems to be what @Dramorian is talking about. I guess the solution is to include the filename in the content-disposition header.

note: this only applies to clicking "Download" in the sidebar. The images' URLs remain unchanged. You can inspect the Download button's HTML to see what the value of 'download' is (and thus what the filename should be set to).

I encountered this a few years ago with Twitter, since their pbs.twimg.com domain is separate from the main twitter.com domain. As I found out back then, the download attribute stopped working because browsers were then not complying with that attribute for cross-domain requests for security reasons. Which is why I had to migrate to using a Javascript solution to download the images to memory, and then saving them to disk with the desired filenames from there. I'm not sure if there is a way to disable this behavior by browsers, and that behavior might just be baked in from then on.

1