umbraco / Umbraco-CMS

Umbraco is a free and open source .NET content management system helping you deliver delightful digital experiences.
https://umbraco.com
MIT License
4.41k stars 2.66k forks source link

MediaPicker treats file as folder #6441

Closed roeermose closed 3 years ago

roeermose commented 4 years ago

It is not possible to select the media in the mediapicker when using belowconfiguration. The media is treated as a folder eventhough it is a file.

Specifics

Version 7.15.3 Chrome 76.0.3809.132 Checked in Firefox 67.0.4

Have been tested on a clean 7.15.3 by support with same results.

Steps to reproduce

Create a doc-type, create property with MediaPicker editor, set "Pick multiple items" = true, "Pick only images" = false, "Disable folder select" = true Create a media where you do not upload a file. Create a node using the new doc-type and try to select the media.

Expected result

I expected to be able to select the media.

Actual result

The media was not selectable, and when you tried to select it, then you would be presented with an empty folder.


_This item has been added to our backlog AB#7087_

nul800sebastiaan commented 4 years ago

Hey @roeermose - apart from the selected file not really having a file extension, this all works for me, not sure what I'm doing differently?

image

roeermose commented 4 years ago

Hey @nul800sebastiaan - have you set the specfic configuration for the MediaPicker (default works fine, but the specific configuration does not) image image image

nul800sebastiaan commented 4 years ago

Aha! Yeah, I did misread the configuration necessary, after updating it, I can't pick the empty item either.

We'll have a look!

stevemegson commented 4 years ago

In 7.15, the media picker's definition of "is a folder" is effectively just "has no umbracoFile value". The current test can't tell the difference between an item which has no umbracoFile property and one where the umbracoFile property has no file selected. Both will behave as folders.

I'd need to check, but my PR #6195 to support thumbnails from other properties may also handle having no file selected. I think it will make mediaPath null when there's no property and an empty string when the property has no selected file.

There may also be a javascript tweak needed make sure that an empty string as mediaPath is enough to make the item "not a folder".

andersbrohall commented 4 years ago

Is this related? #7317 :)

banarualexandru commented 4 years ago

Prerequisites: I'm using BlobStorage from Azure for storing the media files.

My findings regarding this issue. Problem 1 After update from 7.12 to 7.15.3 The cmsMedia table is missing all the files. Just some were migrated after the normal migration. Solution

declare @mediaPaths Table( ids int Primary Key Identity(1,1) ,mediaPath nvarchar(1000) ,nodeId int )

INSERT @mediaPaths SELECT cmsPropertyData.dataNvarchar as mediaPath, umbracoNode.id as nodeId FROM cmsPropertyData INNER JOIN cmsPropertyType ON cmsPropertyType.id = cmsPropertyData.propertytypeid INNER JOIN umbracoNode ON umbracoNode.id = cmsPropertyData.contentNodeId WHERE cmsPropertyType.Alias = ('umbracoFile') AND umbracoNode.id IN (SELECT umbracoNode.id FROM umbracoNode INNER JOIN cmsContent ON cmsContent.nodeId = umbracoNode.id INNER JOIN cmsContentType ON cmsContentType.nodeId = cmsContent.contentType INNER JOIN cmsPropertyType ON cmsPropertyType.contentTypeId = cmsContentType.nodeId WHERE cmsPropertyType.Alias = ('umbracoFile') AND umbracoNode.nodeObjectType = ('B796F64C-1F99-4FFB-B886-4BF4BC011A9C')) AND (cmsPropertyData.dataNvarchar IS NOT NULL OR cmsPropertyData.dataNtext IS NOT NULL)

INSERT @rootNodes SELECT id FROM umbracoNode WHERE nodeObjectType = 'B796F64C-1F99-4FFB-B886-4BF4BC011A9C' AND id NOT IN (SELECT nodeId FROM cmsMedia)

SET @i = 1 SET @numrows = (SELECT COUNT(*) FROM @rootNodes) IF @numrows > 0 WHILE (@i <= (SELECT MAX(idx) FROM @rootNodes)) BEGIN

    SET @nodeId = (SELECT NodeId FROM @rootNodes WHERE idx = @i)
    SET @mediaPath = (SELECT mediaPath FROM @mediaPaths WHERE nodeId = @nodeId)
    --Do something with Id here
    SET @versionId = (SELECT TOP 1 VersionId FROM cmsContentVersion WHERE ContentId = @nodeId ORDER BY VersionDate DESC)
    PRINT(@versionId)
    PRINT(@nodeId)
    INSERT INTO cmsMedia(nodeId, versionId, mediaPath) VALUES(@nodeId, @versionId, @mediaPath)

    SET @i = @i + 1
END

 When [this PR](https://github.com/umbraco/Umbraco-CMS/pull/6195) made by Stevemegson will be merged, this will be done automatically by Umbraco migrator.
@nul800sebastiaan are there any reasons why this PR wasn't merged to v7/dev branch?
This workaround fixes the existing media files, but the thumbnail is still not shown, as is analyzed [issue-5847](https://github.com/umbraco/Umbraco-CMS/issues/5847)
**Problem 2**
When uploading a new image in Media / Media picker it saves `NULL` on `mediaPath` column of  `cmsMedia`.
I didn't find a solution for this.
@nul800sebastiaan , @stevemegson  Any Ideas of some workarounds for this?
I was thinking to listen to `MediaService.Saved` event and save 'manually' that Azure URL to `cmsMedia` table.
EDIT
**Solution**
I found the solution for this:
on `public void OnApplicationStarted(
                UmbracoApplicationBase umbracoApplication,
                ApplicationContext applicationContext)`
 I've added an event listener:
`MediaService.Saved += new FixMediaFiles(applicationContext).OnMediaFilesSaved;`
Inside `FixMediaFiles` I've done this:

public class FixMediaFiles { private readonly ApplicationContext _applicationContext;

    public FixMediaFiles(ApplicationContext applicationContext)
    {
        _applicationContext = applicationContext;
    }

    public void OnMediaFilesSaved(IMediaService sender, Umbraco.Core.Events.SaveEventArgs<IMedia> e)
    {
        foreach (var eSavedEntity in e.SavedEntities)
        {
            UpdateMedia(eSavedEntity);
        }
    }

    private void UpdateMedia(IMedia eSavedEntity)
    {
        const int umbracoFilePropertyTypeId = 6;
        var query =
            "SELECT dataNvarchar FROM cmsPropertyData where propertytypeid=@propertyType AND contentNodeId=@nodeId";
        var args = new
        {
            propertyType = umbracoFilePropertyTypeId,
            nodeId = eSavedEntity.Id
        };
        var cmsPropertyData = _applicationContext.DatabaseContext.Database.Query<CmsPropertyData>(query, args)
            .FirstOrDefault();
        if (cmsPropertyData == null)
        {
            return;
        }

        var updateQuery = "SET [mediaPath]=@mediaPath WHERE nodeId=@nodeId";
        _applicationContext.DatabaseContext.Database.Update<CmsMedia>(updateQuery,
            new {mediaPath = cmsPropertyData.dataNvarchar, nodeId = eSavedEntity.Id});
    }

    [TableName("cmsMedia")]
    class CmsMedia
    {
        public int nodeId { get; set; }
        public Guid versionId { get; set; }
        public string mediaPath { get; set; }
    }
    class CmsPropertyData
    {
        public string dataNvarchar { get; set; }
    }
}
It's dirty I don't like it, but at least it works.

**Problem 3**
The thumbnails are not shown on the media edit image page.
**Solution**
In `umbraco.controllers.js`

_.each($scope.persistedFiles, function (file) { var thumbnailUrl = umbRequestHelper.getApiUrl('imagesApiBaseUrl', 'GetBigThumbnail', [{ originalImagePath: file.file }]); var extension = file.file.substring(file.file.lastIndexOf('.') + 1, file.file.length); file.thumbnail = file.file; file.extension = extension.toLowerCase(); });


Set the thumbnail blob url directly.

**Problem 4**
The thumbnails are not shown in 'Select Media' dialog.
**Solution**

I've returned the blob URL directly.

I hope this will help somebody until the team will release a new version with all the right fixes.

Thanks

mjbarlow commented 4 years ago

I'm going to crosslink this issue with Courier https://github.com/umbraco/Umbraco.Courier.Issues/issues/14 as it is the same problem when couriering images.

"The media was not selectable, and when you tried to select it, then you would be presented with an empty folder."

wakeup2k5 commented 4 years ago

I noticed this issue (thumbnails not showing, unable to pick media) after upgrading from 7.14.0 to 7.15.4.

For us, I was able to narrow it down to an alternate media folder being configured.

I replicated the issue using a stock Umbraco 7.15.4 install (Visual Studio, NuGet install, Default Starter Kit). Everything worked fine by default. I was able to upload imagery, select it using a Media picker, etc.

Then I created a '/testmedia/' folder and modified the FileSystemProviders.config, as follows...


<Provider alias="media" type="Umbraco.Core.IO.PhysicalFileSystem, Umbraco.Core">
    <Parameters>
      <add key="virtualRoot" value="~/testmedia/" />
    </Parameters>
</Provider>

Immediately after this, I was still able to upload imagery, but I was not able to select it. It seemed to treat the newly uploaded imagery as a folder.

Would a fix for this (accounting for FileSystemProviders.config changes) be within scope of this existing issue, or should I create a new issue?

stewartellis commented 4 years ago

When is 7.15.5 coming? Would really like a fix from HQ instead of rolling our own. Thanks

deMD commented 4 years ago

I noticed this issue (thumbnails not showing, unable to pick media) after upgrading from 7.14.0 to 7.15.4.

For us, I was able to narrow it down to an alternate media folder being configured.

I replicated the issue using a stock Umbraco 7.15.4 install (Visual Studio, NuGet install, Default Starter Kit). Everything worked fine by default. I was able to upload imagery, select it using a Media picker, etc.

Then I created a '/testmedia/' folder and modified the FileSystemProviders.config, as follows...


<Provider alias="media" type="Umbraco.Core.IO.PhysicalFileSystem, Umbraco.Core">
    <Parameters>
      <add key="virtualRoot" value="~/testmedia/" />
    </Parameters>
</Provider>

Immediately after this, I was still able to upload imagery, but I was not able to select it. It seemed to treat the newly uploaded imagery as a folder.

Would a fix for this (accounting for FileSystemProviders.config changes) be within scope of this existing issue, or should I create a new issue?

This issue also seems to be present in Umbraco 8.5.5

hfloyd commented 4 years ago

I'm disappointed to see that this fix didn't make it into 7.15.5 as originally planned....

stewartellis commented 4 years ago

HQ - a hotfix or quick turn around would be most welcome. This is a major issue. Thank you

RLuhse commented 4 years ago

This particular issue is affecting a large number of people, so a quick fix would be very much appreciated. It looks as though it was first reported almost a year ago...

ItagMichael commented 4 years ago

Any confirmed hotfix for timeframe for 7.15.6 with this fix? This is affecting us significantly.

jattwood commented 4 years ago

I was waiting and waiting for this fix in 7.15.5, really wish it was a hot fix. This is impacting multiple clients and I don't have answers for them. Please make this a priority with thanks!

GingerSquirrel commented 4 years ago

If anyone is struggling with this error I put in a temporary fix of adding a file upload property to to my media item and giving it the alias 'umbracoFile' and making it required. The user just has to upload an empty bugfix.txt file to make it work.

It is definitely not a pretty fix but it is better than me hard-coding media into the site. You will also have to re-save all your current media for it to be effective on them.

vipervf1 commented 4 years ago

Yes, we are still waiting on this bug fix as well.

stewartellis commented 4 years ago

A polite reminder to HQ - this bug affects a paid product - namely courier. A timely fix seems like it should be a done deal.

Thanks

jrguay commented 4 years ago

Hello!

I know @Shazwazza worked on this and mentioned needing further discussion. Is there an ETA for releasing?

Thank you!

nul800sebastiaan commented 4 years ago

Just as a note, we're working on it in this sprint (ending the 28th). To set expectations: I am not sure when exactly we can do a release but it should hopefully be quite soon after the fix is made.

Shazwazza commented 4 years ago

Ready for review https://github.com/umbraco/Umbraco-CMS/pull/8520

The build output with artifacts will be here (once successfully built) https://dev.azure.com/umbraco/Umbraco%20Cms/_build/results?buildId=46124&view=results , we'll need people to test this out before it can be shipped so please let us know on the PR https://github.com/umbraco/Umbraco-CMS/pull/8520 what your results are. Thanks!

hfloyd commented 4 years ago

@Shazwazza - It wasn't exactly clear on that page where to get a copy of the updated files for testing. The "Artifacts" option only shows 8.7 items.

nul800sebastiaan commented 4 years ago

@hfloyd Are you sure? Clicking on the files gives me

image

Specifically the link would be: https://dev.azure.com/umbraco/Umbraco%20Cms/_build/results?buildId=46124&view=artifacts&type=publishedArtifacts

hfloyd commented 4 years ago

huh. Your direct link works. The original page I was looking at shows:

image

and it wasn't clear where to click for the downloads.

Thanks

nul800sebastiaan commented 4 years ago

Ah yeah, they changed it recently from "artifacts" (which is a word that has a meaning) to an icon of a box saying "4 published" 🤷

nul800sebastiaan commented 4 years ago

Aha I never even saw the artifacts on the left hand side either haha! I understand the confusion.

They get bundled here now

image

hfloyd commented 3 years ago

@nul800sebastiaan I wasn't able to get to this before, and now the Build seems to have disappeared. Can you direct me to the build and I will do a community review this week? Thanks!

timeverts commented 3 years ago

I believe I might be encountering a similar issue having just upgraded an Umbraco 7.6.0 site to Umbraco 7.15.7. I am also using Azure Blob storage for media items and both the media picker in the RTE field ('Link to Media') and the standalone media picker seem to have the problem where the custom media type is being treated as a folder rather than a file by the pickers.

@nul800sebastiaan, I see a fix is now slated for a 7.15.8 release which might still be a long way off. Do you have a hotfix for this issue in the mean time?

drbldgtl commented 3 years ago

Hi, just to report we also experience this issue when a media type has multiple Upload properties. Not sure if intended fix for this will also resolve this issue.

Ankurtrue1 commented 3 years ago

Hi @nul800sebastiaan

Issue with MediaPicker unable to pick images. I upgraded my Umbraco Version from 7.12.2 to 7.15.5. Since 7.15.8 is not released, I cannot use that version.

However I am facing an similar issue, as mentioned in the above details, i.e. I cannot add the Media Picker images to the content. When I try to add an Image which is setup using an ImageCropper. The Media folder uploads it correctly, but cant use it to assign in the content. It just keeps on adding same like a folder.

Can someone please advise a workaround. I am just using simple file system as source for Media

Below are the image for Media and the problem I have referred above.

Content-Adding Image_Not_Working ImageCropper-MediaUpload

Kindly help me on this.

Regards, Ankur

umbrabot commented 3 years ago

Hiya @roeermose!

Thanks for reporting this issue. It might have been a while since you heard from us since a lot of things are happening at the moment.

Right now, we're in the process of building Umbraco version 9 and we're now shifting our focus to exclusively work on v8 and v9. From now on Umbraco 7 is in security mode, which means we will no longer fix issues nor merge pull request unless they are severe security issues. You can read all about this in our long term support and end of life policy.

This means that this issue will be closed and no longer looked at by the team. We realize this might be disappointing and we do apologize for not coming to a proper conclusion on this one. We hope you understand that we need to focus our active development somewhere and that means our efforts will go to the current and the future versions of Umbraco.

If it makes sense to look at this issue still for version 8, or even version 9, we'd love it if you reported it as a new issue so it can get the proper attention.

Thanks, from your friendly Umbraco GitHub bot 🤖 🙂

marcoteodoro commented 1 year ago

Hi @nul800sebastiaan / @Shazwazza, I'm I right to assume this was never merged into a release branch?