let rootUrl = 'https://example.sharepoint.com/'
$.ajax({
url: `${rootUrl}_api/web/lists/getByTitle('videos')/items?$select=Id,Title,VideoSetDescription&$filter=ContentType eq 'Video'`,
type: 'GET',
headers: {
accept: 'application/json;odata=verbose'
},
success: res => console.log(res.d.results),
error: err => console.log(JSON.stringify(err))
})
i am getting the filename as example., how can i get the filename with extension
like example.mp4
also i need to get the Id,Title and VideoSetDescription too.
In your case the query returns the list of items which corresponds to so called video sets (filter by Video content type). Which in turn represent the containers where one or more files are actually stored. Refer Video Experience in SharePoint 2013 on how videos organized in Assets library for a more details.
Having said that you could append &$expand=Folder/Files expression to your query which tells to return uploaded files along with the items.Then file name could be printed like this:
success: response => {
response.d.results.forEach( item => {
console.log(item.Folder.Files.results[0].Name); //print first uploaded file
});
},
To retrieve only the list of items associated with uploaded files the following query could be utilized:
/_api/web/lists/getByTitle('<Assets Library>')/items?$select=FileLeafRef&$filter=ContentType eq 'Video Rendition'
Related
I'm processing a table of banking/statement entries that have been exported from another system via a CSV file. They are imported into a view and checked for duplicates before being presented to the user in a HTML table for final review.
Once checked they are sent via AJAX to the server so they can be added into a Django model. Everything is working OK including CSRF but I cannot access the POSTed variable although I can see it!
Unfortunately making a hidden form isn't viable as there are 80+ rows to process.
My Javascript looks like:
$.ajax({
type: 'POST',
url: '......./ajax/handleImports/',
data: entriesObj,
success: function (data) {
if (data.response && data.response) {
console.log("Update was successful");
console.log(data.entries)
} else { ... }
},
error: function() { ... }
where entriesObj is
var entriesObj = JSON.stringify({ "newentries": newEntries });
console.log(entriesObj)
and when dumped to console.log looks like:
{"newentries":[{"Include":"","Upload ID":"0","Date":"2019-01-09", ... }
Now in view.py when I return the whole request.POST object as data.entries using
context['entries'] = request.POST
return JsonResponse(context)
I get
{"{"newentries":[{"Include":"","Upload ID":"0","Date":"2019-01-09", ... }
but if I try and retrieve newentries with:
entries = request.POST.get('newentries', None)
context['entries'] = entries
return JsonResponse(context)
the console.log(data.entries) will output null?
How am I supposed to access the POSTed entriesObj?
The data is JSON, you need to get the value from request.body and parse it.
data = json.loads(request.body)
entries = data.get('newentries')
I'm calling this dataset:
http://data.edinburghopendata.info/api/action/datastore_search?resource_id=4cfb5177-d3db-4efc-ac6f-351af75f9f92
with an AJAX call :
var data = {
resource_id: '4cfb5177-d3db-4efc-ac6f-351af75f9f92',
filters: '{"BankTypeNa": "Packaging", "BankTypeNa": "Compost Bins"}',
limit : 4757
};
$.ajax({
url: 'http://data.edinburghopendata.info/api/action/datastore_search',
data: data,
dataType: 'jsonp',
success: function(data) {
markers = data.result.records;
showMarkers();
}
});
which is giving results only for the second filter.
http://data.edinburghopendata.info/api/action/datastore_search?resource_id=4cfb5177-d3db-4efc-ac6f-351af75f9f92&filters={%22BankTypeNa%22:%20%22Packaging%22,%20%22BankTypeNa%22:%20%22Compost%20Bins%22}
Is there a way, or another parameter I could use to get both "Packaging" and "Compost Bins" in my search results?
Would be nice if somebody can prove me wrong, but its not possible. In theory you would just put the two values in an array as the value for the BankTypeNa key, e.g.
filters: '{"BankTypeNa": ["Packaging", "Compost Bins"]}'
But this doesn't work for text columns (an SQL error results). It does work for numeric ones [1]. It would be good to submit an issue on that at github.com/ckan/ckan.
I would use the datastore_search_sql endpoint instead, i.e.
var data = {
"resource_id": "4cfb5177-d3db-4efc-ac6f-351af75f9f92",
"sql": "SELECT * FROM \"4cfb5177-d3db-4efc-ac6f-351af75f9f92\" WHERE \"BankTypeNa\" LIKE 'Packaging' OR \"BankTypeNa\" LIKE 'Compost Bins'",
"limit": 4757
};
[1] CKAN: delete a list of records within the DataStore in a single query
I'd like to know if it's possible to get exact binary data using callback from drive.files.get method of NodeJS Google API. I know that object returned by calling this API endpoint is a normal request object that could be e.g. piped like this:
drive.files.get({
fileId: fileId,
alt: 'media'
}).pipe(fs.createWriteStream('test'));
However I would like to know if it's possible to get binary data from within callback using this syntax:
drive.files.get({
fileId: fileId,
alt: 'media'
}, function(err, data) {
// Here I have binary data exposed
});
As far as I know, it should be possible to get that kind of data from request during its creation, passing {encoding: null} in request options object like this:
var requestSettings = {
method: 'GET',
url: url,
encoding: null // This is the important part
};
request(requestSettings, function(err, data) {/.../})`
however it seems that Google obscures this configuration object in its library.
So my question is - is it possible to do so without interfering/hacking the library?
Ok, so i found answer that could be useful for others :)
Aforementioned drive.files.get method returns Stream object, so it could be directly handled using proper event handlers. Then, buffer parts could be concatenated into one part and sent back in callback like this:
var stream = drive.files.get({
fileId: fileId,
alt: 'media'
});
// Build buffer
var chunks = [];
stream.on('data', (chunk) => {
chunks.push(chunk);
});
stream.on('end', () => {
return cb(null, Buffer.concat(chunks));
});
I'm using uploadify in my MVC3 project. It works fine to upload multiple files and saving to folders as well.
How to pass the path of the uploaded file to controller action ? -- I need to pass it to the ExtractingZip action of my controller.
To extract the contents of the .zip file, I'm using DotNetZip Library.
Here is what i've tried so far.
$('#file_upload').uploadify({
'checkExisting': 'Content/uploadify/check-exists.php',
'swf': '/Content/uploadify/uploadify.swf',
'uploader': '/Home/Index',
'auto': false,
'buttonText': 'Browse',
'fileTypeExts': '*.jpg;*.jpeg;*.png;*.gif;*.zip',
'removeCompleted': false,
'onSelect': function (file) {
if (file.type == ".zip") {
debugger;
$.ajax({
type: 'POST',
dataType: 'json',
url: '#Url.Action("ExtractingZip", "Home")',
data: ({ fileName: file.name}), // I dont see a file.path to pass it to controller
success: function (result) {
alert('Success');
},
error: function (result) {
alert('error');
}
});
}
}
});
Here is my controller action:
[HttpPost]
public ActionResult ExtractingZip(string fileName,string filePath, HttpPostedFileBase fileData)
{
string zipToUnpack = #"C:\Users\Public\Pictures\Sample Pictures\images.zip";// I'm unable to get the filePath so i'm using the path.
string unpackDirectory = System.IO.Path.GetTempPath();
using (ZipFile zip1 = ZipFile.Read(zipToUnpack))
{
// here, we extract every entry, but we could extract conditionally
// based on entry name, size, date, checkbox status, etc.
var collections = zip1.SelectEntries("name=*.jpg;*.jpeg;*.png;*.gif;");
foreach (var item in collections)
{
item.Extract(unpackDirectory, ExtractExistingFileAction.OverwriteSilently);
}
}
return Json(true);
}
[HttpPost]
public ActionResult Index(IEnumerable<HttpPostedFileBase> fileData)
{
foreach (var file in fileData)
{
if (file.ContentLength > 0)
{
string currpath;
currpath = Path.Combine(Server.MapPath("~/Images/User3"), file.FileName);
//save to a physical location
file.SaveAs(currpath);
}
}
}
You don't need to pass the zip's filepath when it's uploaded. The filepath would be from the clients machine right? Your application on your server has no knowledge or access to the clients file system.
The good news is you don't need it. You already have the contents of your file in memory. I have never used donetzip but some quick googling reveals that you can read zips directly from a stream.
Check out these links:
Cannot read zip file from HttpInputStream using DotNetZip 1.9
Extracting zip from stream with DotNetZip
So using those posts as a base to go off of... It looks like you should be able to change your code like so:
string zipToUnpack = #"C:\Users\Public\Pictures\Sample Pictures\images.zip";// I'm unable to get the filePath so i'm using the path.
string unpackDirectory = System.IO.Path.GetTempPath();
using (ZipFile zip1 = ZipFile.Read(zipToUnpack))
{
....
Changes to...
string unpackDirectory = System.IO.Path.GetTempPath();
using (ZipFile zip1 = ZipFile.Read(fileData.InputStream))
{
....
Let me know if that helps.
First of, due to security reasons you have no access directly to clients machine. While a user uploads some files, web browsers make one or tow (usually 1, according to RFC) stream and server-side script reads that stream, so do not waste your time to get files directly from user's local machine's filepath.
To extract archives (s.a: Zip, Rar) I highly recommend you to use SevenZipSharp. It works really good and easy with Streams and also many compression formats.
As they documentation you can extract stream like this:
using (MemoryStream msin = new MemoryStream(fileData.InputStream))
{ ... }
Ok, I am semi-new to ExtJS, and I am building a program that has "inputs" that are listed in a grid, and in my DB these inputs can be linked to "symptoms".
I am trying to create a function that will take in the id of the input and grab all of the symptoms from the database that are linked to that symptom, and list them in a field set.
It works fine when I click on an input that is only linked to one symptom, but if the input is linked to more than one symptom, then the error says.. "invalid property id"
This is what I have for my function.
function listSymptoms(inputID){
Ext.Ajax.request({
url: "../../inc/project4.php?list=symptoms",
reader: new (Ext.data.JsonReader)({
root: "symptoms",
inputid: "id"
}),
params: {
inputid: inputID
},
method: "POST",
success: function (f, a){
var jsonData = Ext.util.JSON.decode(f.responseText);
symptomsFieldSet.body.update(jsonData.data.name);
},
failure: function (f,a){
Ext.Msg.alert('There was a problem opening your message.');
}
});
}
I have the inputID for the function being passed in when the user clicks on one of the inputs that are held inside the grid.
I believe that my problem has something to do with this line..
symptomsFieldSet.body.update(jsonData.data.name);
I am just stumped on how to handle this. Do I need to create a data store like I have for grids? Or is there an easier way to do this?
ANY help is appreciated! thanks in advance.
I think you need to rethink the structure of your JSON response object. You can send this in your JSON response to your request. If you are using Ext.util.Ajax calls instad of a form, you'll need to decode this JSON response string using the util method Ext.util.JSON.decode(). Check out the API Documentation
{
success: true,
msg: {text: 'this can be used for error message handling' },
data : [
{id:1,
chiefComplaint: 'head hurts',
symptoms: [
{symptomID: '740.1', text: 'Headache'},
{symptomID: '12352135'. text: 'and so on'}
}
]
]
}