How to get relative path to a file in cache - symfony

I'm trying to get the relative path to a file inside a app/cache dir.
I've tried via custom config file using:
parameters:
output_dat_path : %kernel.root_dir%/cache/%kernel.environment%/myfile.dat
Also I tried:
$kernel = $this->get('kernel');
$path = $kernel->getRootDir() . '/cache/' . $kernel->getEnvironment() . 'myfile.dat';
Both ways generate absolute paths, that both work fine using them inside a controller or service, but, I need a relative path to generate a link for the user.
I'm thinking to move the file to the web directory in my service and use asset in the template to generate the link, but the file is private for every user and I don't want to expose it.
Any thought?
Thanks in advance.
UPDATE
I solved this as follows:
User, once authenticated, generates his file. If the file doesn't exists, is generated. If it exists, the controller checks the user rights, time, etc. and returns the file.
If the system has to be generated, the file is created in a private folder and an encrypted name is generated. The encrypted name is generated using base_64 and some changes after that.
The system shows to the user a link. That link is something like /get/privatefile/eDfa...23Hn
When the user clicks on it, the controller checks the user, time from creation, etc.
If all is fine the controller returns the file.
I made this because the file must be created once, and be available for a short period of time and after must be deleted. If an user pass the link to other person, the checksum of the encrypted name fails and the file cannot be accessed.
I am sure that this is not the best solution but it works right know.

Related

How to retrieve asp.net media / resources based on logged in user?

I have an asp.net web api project using token based authentication. my app uploaded and retrieve images and I keep file path in table_myfiles along with the uploaded user ID.
I would like the user to access only the files he have uploaded, which I can identify from the table.
How to protect my resources to restrict access to only to the user based on table_myfile ? And not to anyone without logging in or direct link / path ?
I have been searching for any possible solution for a week now , I think I should implement a middleware to manage access. But I couldn’t find any resources on how to implement the same.
Currently my api shows all resources just by directly accessing the file path/link.
The simple apporach is to remove the vitural folder, or that folders from the web site folders. That way, no simple URL exists for any of the files.
So, for a user to get/see/use/download a file? You present say a listview or some kind of grid (or repeater) that displays and lists out the files.
Then, when they want to download or view a file?
You use response.write and stream the file down to the client side.
Remember, on the server, code behind uses 100% clean and correct windows file paths. For any web based URL, then that folder must be in a valid path of the web site. When they type in a valid URL, it eventually gets translated to that given folder in the site (or a external folder provided when you create a mapped "virtual" folder in IIS. However, if you don't provide that virtual folder, or the folder is NOT in the web site file/folder sets, then no valid URL's exist. However, that folder can be directly used and hit with code behind - any valid server path/folder name is allowed in code behind.
Because when streaming the file, you need path name, file name, AND ALSO the "mine" type. Thankfully, .net 4.5 or later has this ability.
so, from a database (table) I display the file names like this:
But, if you click on the preview image, that is a image button.
The code behind simply gets/grabs the file name from the database.
I then download (stream) the file to the browser side like this:
if (File.Exists(strInternalFullPath))
{
string strConType = MimeMapping.GetMimeMapping(strInternalFullPath);
binFile = File.ReadAllBytes(strInternalFullPath);
Response.ContentType = strConType;
Response.AppendHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(strWebUrl));
Response.BinaryWrite(binFile);
Response.End();
}
else
MyToast2(this, btnLink.ClientID.ToString, "File Not found", "We no longer have this file avaiable.");
so, this buttion behaves 100% like a link, but there are no existing URL's or path name that points to the files folder from a web based URL.
Remember:
Web based URLs - they auto map from the web site URL to a existing folder.
You can use server.MapPath("some url to file") to "translate" this to a internal file name.
Code based files:
In your .net code (code behind) ANY file name is a standard plane, jane file name that points to a file on the server.
so, once we have that file name from the database, you can steam the file as if the user clicked on a link. But you never have to expose the actual file name, or file path. And no such valid URL's exist on the web site, since you do NOT have that files folder in the web site folder hierarchy - but placed that folder outside of the web site.
As long as that folder is outside of the web folders, and as long as you don't setup a virtual folder that points to that folder outside the web folders?
Then code behind can STILL get/grab/see/use any file on the server. that code uses a full valid windows file name, - but the web site will have no mapping to such a folder - hence no valid URL's will exist or can be typed in.

How to add push notification for a particular folder in google drive to get all updates that happen for all the file inside the folder

I want to set a push notification for a folder in google drive using google api such that any changed made to any file inside that folder than i get a call -back.
What I know is that its not possible at this moment. Instead of that you can create changes hook and get informed if ANY file on drive is changed. After theat run file search request to find all files within given folder by passing its ID, ie:
"'<folder_id>' in parents"
where <folder_id> is id of the folder where you want to look for changes. You can then look for last modified date and compare to your own cache, for example stored on your server in cache files. If file is newer than do with it whatever you want (and of course update cache).
please refer to:
https://developers.google.com/drive/v2/reference/changes/watch
https://developers.google.com/drive/web/search-parameters

MS Access error 6124 when using UNC path to a .doc template

I am using the Word Document template to create a letter from Access database.
From the form in Access I can select records which are used to generate a letter based on predefined template.
The template is located in the server. The users have access to that location but it is not mapped in their systems.
So my problem starts when I set the UNC path to the template in the code:
Set doc = oWord.Documents.Open("\\srv01\Tool\Templates\Letter.doc")
I get an error 6124: You are not allowed to edit this selection because it is protected.
When I set the path to the mapped drive it works fine:
Set doc = oWord.Documents.Open("T:\Tool\Templates\Letter.doc")
But the thing is it works only for me because I have it mapped, but as I mentioned above my users don't have it mapped.
So is there any workaround?
P.S. I thought about creation of a template folder in the user's local drive but I want to store it in the safe location and don't want to face with sudden deletion or other corruption of this folder by the user.

Creating a new file without using a ServletContext

Assume I want to write to a new file created within the space of my webapp.
One way would be use getServletContext().getRealPath("/") and use that String to create a new file on the server. However, often I come across advice like not using getServletContext().getRealPath("/").
Can someone please let me know of another way to write a new file within my webapp?
Many thanks.
Have some configuration property containing the absolute path of a directory outside of the webapp and web server path, read this path from the configuration property, and write to this directory.
To serve files from this directory, write a servlet that takes the name or ID of this file as parameter, reads the file from the directory, and sends its content to the response.
This will
work even if the app is deployed as a war file and never unzipped to the file system
allow you to redeploy the next version of the app or server without deleting all the uploaded/created files
allow you to add whatever control you want on the uploaded/created files, instead of making them available to everyone
In short, treat these files as data, stored in a database which happens to be the file system instead of a SQL database.

Get the uploaded document url through alfresco

I am very new to alfresco(using version 3.4). I have written a document library action to validate the uploaded file. Now I want path of uploaded file so that I can pass it to my service to validate. Can any one tell me how could I get the downloadable path of a document ??
THanks....
I don't know how you've build your action. But on the client side Javascript you could access file.path.
On the repository side webscript, the normal action imports action.lib.js.
In which the path variable is available.
If you take a look at e.g. Backup Action in the googlecode project share-extra's then you'll probably will know what I mean.
The URL download path?
If you know the nodeRef of the document, you can construct the path yourself.
Here's an example:
http://localhost/share/proxy/alfresco/api/node/content/versionStore/version2Store/169c2842-6bc8-4ace-9b9f-1a46aebb100b/MyFile.pdf?a=true
Everything up to and including the "version2Store" is fixed, and then you have the nodeRef/file part. That's the download link for a document (assuming the user is logged in and can have access to the document or the document is accessible for guests.

Resources