Can we Delete uploaded files from dam - adobe

I need to delete uploaded files from DAM Asset programmatically. Can we delete particular file node from DAM?
Path:-
/content/dam/nextgen/Ehub-POD/....
Inside Ehub-POD , I'm creating a folder and upload files. In jsp page I'll select particular file and need to delete the file from dam as well as from the jsp.

Let's Imagine we have the following image in dam:
/content/dam/nextgen/Ehub-POD/image1.jpg
To remove it use jcr Session:
session.removeItem("/content/dam/nextgen/Ehub-POD/image1.jpg")
if (session.hasPendingChanges()) {
session.save();
}
Image from dam will be removed, now you need to run query to find out where image was used and delete fileReference property:
Workspace workspace = session.getWorkspace();
QueryManager qm = workspace.getQueryManager();
Query query = qm.createQuery("/jcr:root/content/websitename/*[#fileReference='/content/dam/nextgen/Ehub-POD/image1.jpg']", Query.XPATH);
QueryResult queryResult = query.execute();
result = queryResult.getNodes();
while (result.hasNext()) {
Node node = result.nextNode();
node.getProperty("fileReference").remove();
}
or you can delete all info about image, received
node store info about cropping, fileReference and etc:
while (result.hasNext()) {
Node node = result.nextNode();
node.remove();
}
and don't forget to save your repository changes
if (session.hasPendingChanges()) {
session.save();
}

Another way to do it via CURL:
You can do a CURL DELETE request to the image path to remove it. Also, you can find all references to an image using CURL via following command:
http://localhost:4502/bin/wcm/references.json?path=/content/dam/nextgen/Ehub-POD/test-image.png
This will give you references of all the places where this image is used (except CSS or JS).

Related

Is there a way to add more information to a node, except the mandatory ones?

I want to add more node information to a network node. Is it possible to share more data besides what's in the node configuration file? Maybe some custom fields, like an encoded logo image or stuff like that.
Thanks
Yes you can.
Inside your module under src folder add a file called config.conf.
Add your values inside of it in the following format:
key1="string_value"
key2=number_value
Inside build.gradle go to the part where you define your nodes, let's say your module name is "my_module"; do this:
cordapp (project(':my_module')) {
config project.file("src/config.conf")
}
Now when you run deployNodes, gradle will generate a file called my_module.conf under build\nodes\my_node\cordapps\config.
To access those values inside your flow:
getServiceHub().getAppContext().getConfig().getString("key1");
As for testing flows; to mimic the custom config file you need to do the following:
Map<String, String> customConfig = new HashMap<>();
customConfig.put("key1", "string_value");
customConfig.put("key2", "int_value");
// Setup network.
network = new MockNetwork(new MockNetworkParameters().withCordappsForAllNodes(ImmutableList.of(
TestCordapp.findCordapp("my_package").withConfig(customConfig))));

How to create dynamic assets in Meteor

I thought this would be easy.
I want to create simple files the user can download by clicking a link.
Write what you want into the servers assets/app folder and then generate a simple link
Download> me!
Writing files into Meteor's server side asset folder is easy. And the download link above will always download a file with the name you specified.
You will get a yourNewFile.txt in the client's download folder. But, unfortunately its content will not be what you wrote on the server (new.txt).
Meteor has the strange behavior of downloading its startup html page as the content if the name of your content wasn't originally in the public folder. I think this is bug .... put the above anchor into a default Meteor project and click the link .. don't even create a public folder. You get a downloaded file with the name you asked for...
So, if you put stubs in the public folder (you know the names of the assets you are going to create) then you can create them dynamically.
I don't know the names before hand. Is there any way to get Meteor to 'update' its assets list with the new names I want to use?
I know there are packages that can do this. I'd like to just do it myself as above, really shouldn't be this hard.
The public/ folder intended use is specifically for static assets. Its content is served by the node http server.
If you want to dynamically generate assets on the server, you can rely on iron:router server side routes.
Here is a simple example :
lib/router.js
Router.route("/dynamic-asset/:filename",function(){
var filename = this.params.filename;
this.response.setHeader("Content-Disposition",
"attachment; filename=" + filename);
this.response.end("Hello World !");
},{
name: "dynamic-asset",
where: "server"
});
In server-side route controllers, you get access to this.response which is a standard node HTTP response instance to respond to the client with the correct server generated content. You can query your Mongo collections using the eventual parameters in the URL for example.
client/views/download/download.html
<template name="download">
{{#linkTo route="dynamic-asset" target="_blank" download=""}}
Download {{filename}}
{{/linkTo}}
</template>
client/views/parent/parent.html
<template name="parent">
{{> download filename="new.txt"}}
</template>
The linkTo block helper must be called in a context where the route parameters are accessible as template helpers. It will generate an anchor tag having an href set to Router.path(route, dataContext). It means that if our server-side route URL is /dynamic-asset/:filename, having a data context where filename is accessible and set to "new.txt" will generate this URL : /dynamic-asset/new.txt.
In this example we set the current data context of the download template to {filename: "new.txt"} thanks to the template invocation syntax.
Note that target="_blank" is necessary to avoid being redirected to the dynamic asset URL inside the current tab, and the download HTML attribute must be set to avoid considering the link as something the browser should open inside a new tab. The download attribute value is irrelevant as it's value will be overriden server-side.
Here is the raw Picker (meteorhacks:picker) route and method I used to get this running. I've kept it lean and its just what I got working and probably not the best way to do this ... the synchronous methods (like readFileSync) throw exceptions if things are not right, so they should be wrapped in try-catch blocks and the mkdirp is a npm package loaded through meteorhacks:npm package hence the Meteor.npmRequire. Thanks again to saimeunt for the directions.
Picker.route('/dynamic-asset/:filename', function(params, req, res, next) {
console.log('/dynamic-asset route!');
var fs = Npm.require('fs');
var path = Npm.require('path');
var theDir = path.resolve('./dynamic-asset');
var filename = params.filename;
var fileContent = fs.readFileSync(theDir + '/' + filename, {encoding:'utf8'});
res.end(fileContent);
});
The Meteor method that creates the file is
writeFile: function(fname, content) {
console.log('writeFile', fname);
var fs = Npm.require('fs');
var path = Npm.require('path');
var mkdirp = Meteor.npmRequire('mkdirp');
// verify/make directory
var theDir = path.resolve('./dynamic-asset');
mkdirp(theDir);
fs.writeFileSync(theDir + '/' + fname, content);
return 'aok';
}
and the hyper link I generate on the client if the file gets created looks like this:
Download lane file now
I incorrectly stated in my original question at the top that you could use stubs and write files into the assets folder. Its not so .. you will only get back the stub ... sorry.

Loading data from database for BB10

I followed the database creation app on http://developer.blackberry.com/native/sampleapps/ but I can't figure out how can I create the database/retrieve data when my app loads. Can someone help me with good reference books for using sqlite3 with cascades, I can't find any good source for it.
There are a few ways, but I used this one so far (it's not perfect but good enough).
First save customsqldatasource.cpp and customsqldatasource.h inside your /src directory.
Open your applicationui.cpp and add to the top
#include "customsqldatasource.h"
and add this inside ApplicationUI to expose it to QML:
qmlRegisterType<CustomSqlDataSource>("com.myapp.data", 1, 0, "CustomSqlDataSource");
Add LIBS += -lbbdata to your .pro file
add your database in /assets; location is up to you, just make sure it matches source in CustomSqlDataSource
add import com.myapp.data 1.0 to your .qml file
Within attachedObjects add this:
CustomSqlDataSource {
id: asynkDataSource
source: "sql/mydatabase.db"
query: "SELECT * FROM recent_searches GROUP BY fromCity, toCity ORDER BY id DESC"
onDataLoaded: {
if (data.length > 0) {
//use data
}
}
}
Now all you need to do is add the following line inside onCreationCompleted to load it
asynkDataSource.load();
I hope I didn't forget anything. A few important things: /assets folder is read only, therefore your .db is copied to /data folder (this script does it).

How to display images on a page when images are stored outside of web root

When users upload an image, it is stored in the file system but outside of what is publicly reachable.
I am displaying a list of items, and each item has an image associated with it.
How can I display the image when the actual file is stored outside of the wwwroot folder? i.e. it isn't publicly available.
Since the action method is running on the server, it can access any file it has permission to. The file does not need to be within the wwwroot folder. You simply need to tell the action method which image to get.
For instance:
<img src="/mycontroller/myaction/123">
Your action would then look like:
public FileResult MyAction(int id)
{
var dir = "c:\myimages\";
var path = Path.Combine(dir, id + ".jpg");
return new FileStreamResult(new FileStream(path, FileMode.Open), "image/jpeg");
}
Please note that the id is an int which will prevent someone from injecting a path to access different files on the drive/share.
You could do this two ways.
Option 1, you could create a Virtual directory which points to this other Directory. This would then mean that you could access the images via another URL. e.g. Create a Virtual Directory called "OtherImages", then your URL would be;
http://www.mywebsite.com/otherimages/myimage.jpg
Option 2, you could create a simple HttpHandler which can load up the image from the absolute path, then output this in the response. Read up on HttpHandlers and dynamically generating images.

ASP.Net How to access images from different applications

I have 2 different project. One is supposed to upload images (admin) and the other is supposed to show them.
I was writing something like "/Contents/images/image path"... But wait! I will I upload the images from the application into that address?
Any help and suggestions please.
If you have two applications that will interact with the same files, it's probably better to have an ImageController with an action that allows you to upload/download the image rather than storing them directly as content. That way both applications can reference the same file location or images stored in a database and manipulate them. Your download action would simply use a FileContentResult to deliver the bytes from the file. You can derive the content type from the file extension.
Example using a database. Note that I assume that the database table contains the content type as determined at upload time. You could also use a hybrid approach that stores the image metadata in a database and loads the actual file from a file store.
public class ImageController : Controller
{
public ActionResult Get( int id )
{
var context = new MyDataContext();
var image = context.Images.SingleOrDefault( i => i.ID == id );
if (image != null)
{
return File( image.Content, image.ContentType );
}
// or you could return a placeholder image here if appropriate.
throw new HttpException( 404, "The image does not exist" );
}
}
An alternative would be to incorporate your administrative interface in an area of the same application rather than in a separate project. This way you could reuse the content/images directory if you wanted. I find that when you have dynamic images the database or a hybrid approach works better from a programming perspective since it's more consistent with the rest of your data model.
you could try like this..
Let's assume that all of your images are in Project A and you want to use the same images in Project B.
Open Project B with Visual Studio. In the Solution Explorer, right click your Project Name and select "Add Existing Item...".
Browse to the physical location on disc where your images in Project A are stored and select the files that you want to import.
You'll then be able to access those images from project A in Project B.

Resources