I understand the correct way to reference media files so when media files are replaced no broken links will occur. This is fine for code that runs from an Umbraco MVC view. The issue I am facing is that our editors wish to upload media files and distribute the media link for use in other distribute content mediums that Umbraco does not control. When a media file in Umbraco is replaced the numerical folder is changed and that will break all distributed links to that media file outside of Umbraco.
Is there a special way to handle replacing media files in Umbraco so that the URL will not change at all? For now we are using the URL tracker plug in and creating redirects for any updated and distributed media links; as a work around.
If I understand the issue correctly then I think you will actually need to find the media item in the media section and click on "Remove file" and then upload the new file, which will replace the old one. The new file will of course also need to have the same file-name as the old file that is being removed has. That way the url should remain the same and the file will be uploaded into the same id named folder.
But it's a bit of a tedious process if it's something that needs to be done for many files of course.
Hi Jan, this doesn't work unfortunately. The link listed under the "Info" tab remains the same, but results in a 404. A new URL with a new number is created for the updated version, and we still have to manually update wherever it's linked on the website.
Hmm - Ok, so I just did some investigation on this and here is what I learned.
If you're using the grid to insert an image then you're in fact right that the image change will not happen if you swap the image on the media item. I had to also re-select the image in the grid.
However if one is using a media picker not using the grid then the updated image is visible once it's been swapped and the page has been refreshed.
Even though as you say that the url does not change for the item, the correct url is being fetched in the last scenario.
I'd say that the missing change of the links in the info tab is a bug and perhaps that's why the grid image is not automatically being updated.
I'll try to ask about this in the Gitter chat to figure out whether to report this scenario as a bug or not.
EDIT: I did this test on Umbraco 7.11.1 - Don't know if the behavior is the same on older versions but I suspect that it probably is. And I'm 99% certain it's the same on 7.12 :)
I just tested this on an older Umbraco version (7.7x) and when I swap the image then the url on the "info" tab does in fact change too.
So in some version after the 7.7 release this bug has been introduced. Perhaps it happened after the "Properties" tab was renamed to "Info" for some weird reason :)
However the image in a grid editor does not change. So that might either be expected behavior or another bug.
I hope it all makes sense - I'll file an issue about this and linke to it from here at least.
I wish there was a way we could move a file into a physical media/{id} folder to recover the path of files when the correct procedure is not followed; from within Umbraco.
I have same problem, it is not possible to replace existing media file without changing ID - e.g. /media/ID/filename.pdf.
Every time new ID will be generated (same filename, replace) means it is not possible to replace file without URL change. That is huge problem, because customers communicate some PDF Links to other media and afterwords they can not replace that file.
string filePath = $"D:\\Temp\\testingFile.pdf"; //Path of file to be replaced, try next way if this doesnt works
//string filePath = System.IO.Path.Combine(@"D:\\TestFolder\\", "testing.pdf");
var fileName = Path.GetFileName(filePath );
using (var fileStream = System.IO.File.OpenRead(filePath ))
{
var mediaService = ApplicationContext.Current.Services.MediaService;
var mediaFile = mediaService.GetById(existanceFlag);
mediaFile.SetValue("umbracoFile", fileName, fileStream);
mediaService.Save(mediaFile);
}
I have two Umbraco projects that are both 7.13.2 and in one of them the (/media/ID/filename.ext) ID increments when you replace the file, and in the other project it remains the same and does not increment. It is the same whether you replace the file with one with a different name, or the same name.
Both projects use Azure for blob storage (all our sites do).
In both cases i replace the file by just using the file picker (Browse..) and then save.
I am thinking that a plugin might be responsible for the differing behaviour - the one where the ID increments has USync installed, but i have not found a definite reason why the behaviour is different between them as yet.
Hey there. Did you ever nail down what may be causing this?
I have a client who is experiencing a very similar (the same?) issue.
Namely, if they go to update a PDF file with an updated version, if they specify the same file name, the new version of the file is not uploaded; and if they specify a different file name, the path to the file, of course, changes, so the links would be broken.
I'd love to see a fix for this that doesn't involve moving to a newer version of umbraco (they're stuck on a reasonably old 7.x release), so I'm hoping you managed to figure it out. :)
This make's replacing heading images across every page on a website impossible from a business perspective. The amount of time a business would need to allocate to manually replace every image is just horrendous. This is such a fundamental flaw.
Say you were presented with a website with image resource sizes of 1.5Mb for just a handful of images and you wanted to compress, use a different file format but keep the image name the same.
When an Editor chooses to replace an image in the media section, the first thing I would expect as that user is for all occurances of that image to change everywhere. Isn't that the point of including such a feature?
Replace a media file
I understand the correct way to reference media files so when media files are replaced no broken links will occur. This is fine for code that runs from an Umbraco MVC view. The issue I am facing is that our editors wish to upload media files and distribute the media link for use in other distribute content mediums that Umbraco does not control. When a media file in Umbraco is replaced the numerical folder is changed and that will break all distributed links to that media file outside of Umbraco.
Is there a special way to handle replacing media files in Umbraco so that the URL will not change at all? For now we are using the URL tracker plug in and creating redirects for any updated and distributed media links; as a work around.
Hi Danny
If I understand the issue correctly then I think you will actually need to find the media item in the media section and click on "Remove file" and then upload the new file, which will replace the old one. The new file will of course also need to have the same file-name as the old file that is being removed has. That way the url should remain the same and the file will be uploaded into the same id named folder.
But it's a bit of a tedious process if it's something that needs to be done for many files of course.
/Jan
Hi Jan, this doesn't work unfortunately. The link listed under the "Info" tab remains the same, but results in a 404. A new URL with a new number is created for the updated version, and we still have to manually update wherever it's linked on the website.
Hmm - Ok, so I just did some investigation on this and here is what I learned.
If you're using the grid to insert an image then you're in fact right that the image change will not happen if you swap the image on the media item. I had to also re-select the image in the grid.
However if one is using a media picker not using the grid then the updated image is visible once it's been swapped and the page has been refreshed.
Even though as you say that the url does not change for the item, the correct url is being fetched in the last scenario.
I'd say that the missing change of the links in the info tab is a bug and perhaps that's why the grid image is not automatically being updated.
I'll try to ask about this in the Gitter chat to figure out whether to report this scenario as a bug or not.
EDIT: I did this test on Umbraco 7.11.1 - Don't know if the behavior is the same on older versions but I suspect that it probably is. And I'm 99% certain it's the same on 7.12 :)
Ok, so a quick follow up!
I just tested this on an older Umbraco version (7.7x) and when I swap the image then the url on the "info" tab does in fact change too.
So in some version after the 7.7 release this bug has been introduced. Perhaps it happened after the "Properties" tab was renamed to "Info" for some weird reason :)
However the image in a grid editor does not change. So that might either be expected behavior or another bug.
I hope it all makes sense - I'll file an issue about this and linke to it from here at least.
EDIT: The bug is reported here now http://issues.umbraco.org/issue/U4-11587
/Jan
Thank you for your answer.
I wish there was a way we could move a file into a physical media/{id} folder to recover the path of files when the correct procedure is not followed; from within Umbraco.
Can we use code to replace a file in Umbraco media? So that the reference to the file shouldn't get broke.
I have same problem, it is not possible to replace existing media file without changing ID - e.g. /media/ID/filename.pdf. Every time new ID will be generated (same filename, replace) means it is not possible to replace file without URL change. That is huge problem, because customers communicate some PDF Links to other media and afterwords they can not replace that file.
It is Possible
Yes, that is working if you are doing it programmatically, but try to achieve that over cms ui.
I have two Umbraco projects that are both 7.13.2 and in one of them the (/media/ID/filename.ext) ID increments when you replace the file, and in the other project it remains the same and does not increment. It is the same whether you replace the file with one with a different name, or the same name.
Both projects use Azure for blob storage (all our sites do).
In both cases i replace the file by just using the file picker (Browse..) and then save.
I am thinking that a plugin might be responsible for the differing behaviour - the one where the ID increments has USync installed, but i have not found a definite reason why the behaviour is different between them as yet.
Thx, this hint with usync is great, I have to look for this, because we have usync installed.
Hey there. Did you ever nail down what may be causing this?
I have a client who is experiencing a very similar (the same?) issue.
Namely, if they go to update a PDF file with an updated version, if they specify the same file name, the new version of the file is not uploaded; and if they specify a different file name, the path to the file, of course, changes, so the links would be broken.
I'd love to see a fix for this that doesn't involve moving to a newer version of umbraco (they're stuck on a reasonably old 7.x release), so I'm hoping you managed to figure it out. :)
All the best,
-Sam
No, im afraid the mystery remains ....
This make's replacing heading images across every page on a website impossible from a business perspective. The amount of time a business would need to allocate to manually replace every image is just horrendous. This is such a fundamental flaw.
Say you were presented with a website with image resource sizes of 1.5Mb for just a handful of images and you wanted to compress, use a different file format but keep the image name the same.
When an Editor chooses to replace an image in the media section, the first thing I would expect as that user is for all occurances of that image to change everywhere. Isn't that the point of including such a feature?
is working on a reply...