Uploading images in order of filename

AI-generated summary

The discussion revolves around the issue of images being uploaded in a random order, rather than the order they were selected in. ron_jeremy initially reported the issue and sam acknowledged it as a reasonable feature request.

codinghorror investigated the issue and found that the operating system, not the web browser, is responsible for the file order. The issue arises because the operating system does not respect the order in which files are selected. codinghorror discovered that Windows tends to send files in a weird order, and the only way to get the files in the correct order is to select them in reverse order of number.

Remah further investigated the issue and found that the file selection behavior is not specific to the web browser, but rather a common problem in many applications. The order of upload completion also seems to play a role in determining the final order of the images.

sam proposed a solution to the issue by redoing the image placeholders to include a sequence number, which would allow the images to be inserted into the post in the correct order. sam confirmed that this change would be implemented in a future update, but clarified that it would not change the order in which the operating system sends the files. Instead, it would simply ensure that the images are inserted into the post in the correct order, regardless of upload speeds.

The issue has since been fixed in pull request #6306.

Is it possible to have images that are uploaded & inserted into a post to appear in order by filename?

For example: if I select the following images (1.jpg, 2.jpg, 3.jpg, 4.jpg, 5.jpg) on my computer & upload them into a post (using the editor’s file upload icon) they seem to be inserted in a random order (it’s not by filename or size). This makes inserting images into “How To” posts or tutorials or anything where a timeline needs to be preserved very tedious because images would have to be inserted one at a time in order to preserve the coherency of the post.

Is this a CP setting I’ve missed or just the way things are?

4 Likes

Interesting use case, I think it is a reasonable feature request to sort by name if you are trying to upload multiple things. Though I wonder “if this is the correct default” why is the operating system not taking care of it?

Hi @sam, I’m not sure what you mean by that.

Here’s another example of what I’m trying to explain: if I use my camera to take pics during a 7 day motorcycle ride, all those pics will be sorted by filename (DSC_001, DCS_002, etc.) which presents the chronological order the pics were taken. What I’d like to see is simply for that order to be preserved when selecting those pics & uploading them into a post.

I mean. We are not getting the filenames in random order, we are getting them in the order the operating system supplies them to the web browser.

Here I have selected pics 1.jpg thru 5.jpg & uploaded them to this post:

What order did you click on the files in the operating system. Let’s try a test:

Here’s me clicking on 1.png, then 2.png, then 3.png, in that order, and uploading them:

Looks in order to me..

Let me try again with different images, and I’ll click on them in reverse order, 3.jpg → 2.jpg → 1.jpg

Not entirely sure what happened there, that looks like 2, 1, 3 to me.

Ok, I can understand that. Is there any way to uhhhh change this?

I suggest starting by putting just the target images in a folder by themselves to test.

I select 1.jpg then hold shift & select 5.jpg.

That is usually the case. For example there’d by a GoPro folder with a bunch of images sorted by filename (and thus by timestamp). Selecting 20 images to create a ride report for a multi day ride doesn’t yield the correct chronological order where one could simply add a gap between each image & enter whatever relevant text applies then move on to the next image.

Every image would need to be inserted one. at. a. time.

Let me try shift-selecting all images in this folder. Here goes, shift-select the range.. wait, I already see a problem! Note the circled area in the screenshot:

Now let me try again shift+clicking each one.. wow nope! No change! Windows apparently really wants those files sent in that weird order, maybe it’s a “human sort” issue? Let me try renaming them.. wow! Nope!

Note the filename area again ↑ ↑

:rofl: here’s what works. Click the files you want to upload in reverse order of number. Therefore I am shift-clicking 8, 7, 6, 5, 4 and I get…

Which looks good, and when uploaded..

Upload also looks good. So this is definitely an operating system / browser issue, nothing to do with Discourse.

2 Likes

A pop instead of a shift so the indexes don’t need to be revised?

Hi @codinghorror, I didn’t mean to imply it’s an issue with Discourse. Is there a possible “fix” from the Discourse side of things where attachments could be displayed in order of filename? Apologies if I’m asking for the moon here – it’s just my ignorance talking.

The “fix” is to shift or ctrl click on the files in the correct order as determined by your operating system :wink:

See my screenshots ↑

Yes, I fully understand that. I can tell my users to shift-click & (hopefully) remember to select images in a backwards oder, but I was hoping maybe Discourse could handle this automagically in a future update.

Discourse is handling the files in the correct order that the operating system and browser is passing them to Discourse.

You may wish to file a bug with your OS vendor.

Already on that. Would you suggest starting with “Hey Tim” or “Dear Mr. Cook”?

It’s interesting that both Apple and Microsoft have this weird behavior, isn’t it?

I agree that it is totally bizarre that the OS wouldn’t respect the order in which you clicked or selected the files.

Now that I think of it, I notice the same behaviour when copying files to my NAS. If I select an album folder with a bunch of MP3 files (01 - song title.mp3, 02 - song title.mp3, etc.) they also seem to “land” on the server in random order.

Could it be the browser and not the OS?