How to get filename(with extension) of Video file in callback of AssetPickerConfig
-
19-02-2021 - |
Question
Now it returns only filename without an extension. Content type of file is Video.
The name of file contains only file name without an extension in the Asset dialog.
Is it possible to get filename.extension ?
with(new AssetPickerConfig('testAssetPickerObj'))
{{
DefaultAssetImageLocation='';
CurrentWebBaseUrl='https://xxx/';
OverrideDialogFeatures='';
OverrideDialogTitle='';
OverrideDialogDesc='';
OverrideDialogImageUrl='';
AssetUrlClientID=NWF$("#" + txtURL).attr('id');
AssetTextClientID='';
UseImageAssetPicker=false; //make this false to show Documents instead
DefaultToLastUsedLocation=true;
DisplayLookInSection=true;
ReturnCallback = getFileNameCallback;}}
function getFileNameCallback(dialogResult, returnValue) {
console.log(dialogResult, returnValue);
}
It should be CLIP_11.mp4
Solution 2
Finally I resolved it.
As a video (Content type: Video) is stored in the asset library, they are stored as folders with folder name being the video name. What I am getting is only the name of the folder. The properties (URL, full name) and the video itself are stored within the folder as another content type known as Video Rendition. Getting the actual video can be done using REST api with the following url:
http://siteurl/_api/web/GetFolderByServerRelativeUrl('/Video Name')/Files
function getFileNameCallback(dialogResult, returnValue) {
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + '/_api/web/GetFolderByServerRelativeUrl(\'' + dialogResult + '\')/files',
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success : function(data){ //data will have the video object
var videoServerRelativeURL = data.d.results[0].ServerRelativeUrl;
console.log(videoServerRelativeURL);
},
error : function(args) {
console.log(args);
}
});
}
OTHER TIPS
My test code for your reference:
<script src="/_layouts/15/AssetPickers.js" type="text/javascript"></script>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
<input id="txtURL" type="text" />
<input onclick="fnGetFileName()" type="button" value="Select File" />
<br />
<input onclick="fnReadFile()" type="button" value="Read File" />
<script type="text/javascript">
//fix for requestexecutor bug as mentioned in Mikael's post - begin
$(document).ready(function () {
//Create a object which will be used for the Asset. The name can anything. I have used 'testAssetPickerObj'
with (new AssetPickerConfig('testAssetPickerObj')) {
{
DefaultAssetImageLocation = '';
//CurrentWebBaseUrl will be the url of the site or site collection. My site comllection url is as follows.
CurrentWebBaseUrl = _spPageContextInfo.webAbsoluteUrl;
OverrideDialogFeatures = '';
OverrideDialogTitle = '';
OverrideDialogDesc = '';
OverrideDialogImageUrl = '';
//AssetUrlClientID is the id of the control in which the path of the selected file will be saved. I am saving the path in a text box. And the id is txtURL.
AssetUrlClientID = 'txtURL';
AssetTextClientID = '';
UseImageAssetPicker = false; //make this false to show Documents instead
DefaultToLastUsedLocation = true;
DisplayLookInSection = true;
ReturnCallback = getFileNameCallback;
}
}
$('#txtURL').val('/MyDoc/testdata.xlsx');
});
function getFileNameCallback(dialogResult, returnValue) {
console.log(dialogResult, returnValue);
}
function fnGetFileName() {
//Following is the function which launch the AssetPortalBrowser.aspx automatically.
APD_LaunchAssetPickerUseConfigCurrentUrl('testAssetPickerObj'); return false;
}
function fnReadFile() {
var webServiceURL = _spPageContextInfo.webAbsoluteUrl + '/_vti_bin/copy.asmx?op=GetItem';
var soapMessage =
'<?xml version="1.0" encoding="utf-8"?> \
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" \
xmlns:xsd="http://www.w3.org/2001/XMLSchema" \
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> \
<soap:Body> \
<GetItem xmlns="http://schemas.microsoft.com/sharepoint/soap/"> \
<Url>' + _spPageContextInfo.webAbsoluteUrl + $('#txtURL').val() + '</Url> \
</GetItem> \
</soap:Body> \
</soap:Envelope>';
$.ajax({
url: webServiceURL,
type: "POST",
//SOAPAction: "http://schemas.microsoft.com/sharepoint/soap/GetItem",
dataType: "xml",
data: soapMessage,
processData: false,
contentType: "text/xml; charset=\"utf-8\"",
success: function (data, status, req) {
//debugger;
//var binaryData = $(req.responseText).find("Stream")[0].innerText;
//todo
},
error: function (err) {
alert(JSON.stringify(err));
}
});
}
</script>
Test result:
You could take a reference to this case:https://social.technet.microsoft.com/Forums/en-US/c0d9ac75-644c-47e9-b7c9-2a220646d998/how-to-set-value-of-html-file-input-control-thorugh-js-or-jquery-for-a-file-present-on-sharepoint?forum=sharepointgeneral