How to get file name from Sharepoint Asset Library - rest

How can I get the file name of an image from a SharePoint 2013 Asset Library?
I am trying to write a JQuery/REST snippet to search a subset of images within the library, based on their other column values and display them. I would use FileLeafRef in case of a Document Library, but I couldn't find an equivalent field in Asset Library.
I so far tried the following, neither returns file name:
https:///crm/_api/Web/Lists/GetByTitle('Publication%20List')/items?select=File/Name&expand=File
https:///crm/_api/Web/Lists/GetByTitle('Publication%20List')/items?select=FileLeafRef

There is a typo in your example, in particular $ symbol is missing for $select and $expand query options (more details).
The following rest endpoints demonstrate how to retrieve file name from Assets library:
1) Using FileLeafRef property:
/_api/web/lists/getByTitle('<list title>')/items?$select=FileLeafRef
2) Using File/Name property:
/_api/web/lists/getbytitle('<list title>')/items?$select=File/Name&$expand=File
3) Using Folder/Files property:
/_api/web/getfolderbyserverrelativeurl('<list url>')/files?$select=Name

I believe that yt's still FileLeafRef for an Asset Library. Any chance you could put the relevant code in your question?
Here's the rest endpoint for FileLeafRef:
/_api/web/lists/getByTitle('<list title>')/items?$select=FileLeafRef
Alternatively you could always use the File Name property:
/_api/web/lists/getByTitle('<list title>')/items?$select=File/Name&$expand=File

Related

AssetBundleBuild addressableNames vs assetNames

Can someone help me understand the difference between the AssetBundleBuild.addressableNames and AssetBundleBuild.assetNames?
Also can I use BuildPipeline.BuildAssetBundles with AssetBundleBuild[] parameter to build specific asset bundles and not all of them (the overload without this parameter) ?
AssetBundleBuild.assetNames identifies the exact location and name for bundling an asset. (assume buildMap is of type AssetBundleBuild)
buildMap[0].assetNames[0] = "Assets/Textures/stinky_pupper_smol.jpg";
AssetBundleBuild.addressableNames is an optional nickname for loading the asset its array index corresponds to.
buildMap[0].addressableNames[0] = "DogTexture";
That's all done during build time so during runtime you can load that texture like this (assume bundle is of type AssetBundle):
bundle.LoadAsset("DogTexture");
instead of:
bundle.LoadAsset("Assets/Textures/stinky_pupper_smol.jpg");
For your second question, yes. The overload of BuildPipeline.BuildAssetBundles with an AssetBundleBuild[] as an argument will ignore your bundles identified in the editor:
This variant of the function lets you specify the names and contents
of the bundles using a "build map" rather than with the details set in
the editor. The map is simply an array of AssetBundleBuild objects,
each of which contains a bundle name and a list of the names of asset
files to be added to the named bundle.

how to find path of a node under /etc/tags in AEM?

I want to search a tag under /etc/tags in AEM programmatically.
for ex:
folder structure is like
/etc/tags/
uder tags there are multiple tags
1.20101/ate2
2.73883
3.44qqiw
4.222
if i want to search ate2 i should get /etc/tags/20101/ate2.
You can use QueryBuilder API to query it.
Sample Query would be
type=cq:Tag
path=/etc/tags
nodename=ate2
Sample SQL2 Query for the same would be
select * from [cq:Tag] as s where ISDESCENDANTNODE('/etc/tags') AND NAME(s)='ate2'
One solution is write the query as suggested by rakhi, other is to utilize TagManager API that provides you lot of methods to search tags and once you get Tag instance you could get path from it. Javadocs for TagManager can be found here and for Tag here
For reference you could look at the code here. One thing to keep in mind in case you end up using this approach you will need to work by creating a system user to get ResourceResolver instead of calling resolverFactory.getAdministrativeResourceResolver(null), refer to article here

How to map urls?

I would like to map pages such domain/content/myProject/home.html to domain/home.html. /content/myProject/ is not needed. I have the following code:
String newpath = getResourceResolver().map(page.getPath());
this does not change anything. newpath is stay page.getPath()
how to solve this issue?
Answering as this question as it remains unanswered. Here is an example of how the etc mappings should look like:
Trick is you add 2 entries to sling:internalRedirect as / and /content/example/
AEM first tries to resolve resources with first entry '/'. So non page URLs like /etc/designs, /content/dam etc will be addressed by the first entry. If it is unable to resolve using the first one, it uses the second entry to resolve the page.
This is also the adobe recommended way for URL shortening compared to other techniques like apache redirect.
You need to create map in etc.Then Resource Resolver will take care of trimming the path .
CREATING MAPPING DEFINITIONS IN AEM
In a standard installation of AEM you can find the folder:
/etc/map/http
This is the structure used when defining mappings for the HTTP protocol. Other folders (sling:Folder) can be created under /etc/map for any other protocols that you want to map.
Configuring an Internal Redirect to /content
To create the mapping that prefixes any request to http://localhost:4503/ with /content:
Using CRXDE navigate to /etc/map/http.
Create a new node:
Type sling:Mapping
This node type is intended for such mappings, though its use is not mandatory.
Name localhost_any
Click Save All.
Add the following properties to this node:
Name sling:match
Type String
Value localhost.4503/
Name sling:internalRedirect
Type String
Value /content/
Click Save All.
This will handle a request such as:
localhost:4503/geometrixx/en/products.html
as if:
localhost:4503/content/geometrixx/en/products.html
had been requested.
You can refer here for further documentation http://docs.adobe.com/docs/en/cq/5-6-1/deploying/resource_mapping.html

get folders of a folder in one drive pro (sharepoint) rest api

I am trying to get a list of folders underneath my documents folder using the sharepoint rest api. This seems like it should be very simple but I am having a hard time seeing how to do this from the documentation.
I want to determine if the following folder exists:
[https]://[Site]/personal/[Path to User]/Documents/test
I tried:
[https]://[Site]/_api/web/GetFolderByServerRelativeUrl('/Documents')
gives 'file not found', I would expect to get some json returned that gives me file information etc, how do I determine if the /Documents/test folder has been created with the rest api?
I believe you should try it like this:
[https]://[Site]/_api/web/GetFolderByServerRelativeUrl('Documents')/folders
This should give a list of all of the folder underneath your documents library.
Hope this helps.
Web.GetFolderByServerRelativeUrl method accepts serverRelativeUrl parameter that specifies the server-relative URL for the folder.
Examples
For location:
[https]://[Site]/personal/[Path to User]/Documents
the following REST requests return folder object:
[https]://[Site]/personal/[Path to User]/_api/web/GetFolderByServerRelativeUrl('/personal/[Path to User]/Documents')
or
[https]://[Site]/personal/[Path to User]/_api/web/GetFolderByServerRelativeUrl('Documents')
Note: relative Url to Documents library is specified (not starts with / like in your example)
Please check it your url is valid like and check the url of your document library :
[https]://[Site]/Documents
In your case it should be like, if its Documents library:
[https]://[Site]/_api/web/GetFolderByServerRelativeUrl('/Shared%20Documents')
Or Write full relative path of your URL like
[https]://[Site]/_api/web/GetFolderByServerRelativeUrl('/personal/[Path to User]/Documents/test')

Finding a download URL from the NuGet OData feed

What's the trick for deriving a download URL given an entry in the Packages table in the OData data set?
< content type="application/zip" src="SOME-URL" />
Under the <entry/> node, look for a <content/> node which contains 2 attributes type and src. The src attribute contains the download url. You could use LINQ to XML to get it. Seems easy, right? Oh, and remember to append an XNamespace to the XName when using LINQ to XML to query the nodes.