sails.js: download file in assets directory - download

I create a .xls file in assets/xls directory :
fs.writeFileSync('./assets/xls/data.xls', xls, 'binary');
And I want to download this file :
To get the file url :
var downloadLink = req.headers.host+'/xls/data.xls';
I do not understant why I have a 404 error on this url :
localhost:1337/xls/data.xls

This isn't the recommended practice for storing generated or user-uploaded files. The assets folder is only intended for your site's front-end assets.
If you want to provide download links in your app, you're encouraged to save them in a separate location and add a controller action that streams the requested file to the client. This allows you to add policies to protect those files, and avoids issues source control and with Grunt. See How do I authenticate access to assets folder in sails.js for an example of such a controller action.

Related

strapi - change upload folder location and restrict access to files

Is there a way in strapi to configure location for uploading media and also restrict access to it?
the docs for configuring the middleware lists only one option for changing maxFileSize.
Strapi uses is koa-body and formidable to process files but I couldnt find option to configure path there also.
I'm on strapi v3.6.2.
Restricting access to files: As far as I know, the upload plugin does not support restricting access to files, based on user-permissions authentication. For example, the aws bucket provider expects a public bucket and the local upload provider serves all files indiscriminately. Options for getting around this include:
Making a custom upload provider
Modifying the upload plugin, develop a custom plugin
Fully custom uploads in a strapi model service
....
Upload folder location: Strapi-provider-upload-local picks up a path from the middleware config here. Although I don't know if this variable is used anywhere else and can be (safely) changed in the middleware config file.

Secure upload files in Laravel

I have a Laravel 5 project in which I am uploading files in database in Medium Blob format.
But uploading files in database takes some extra time to execute.
Uploading files in database is a secured way to keep files safe from crawlers or some bots.
I have tried to Upload files to the Public folder. But the crawlers can open these files.
Is there any possible way to upload files in the file system?
So that the Crawlers cannot open these files.
I want these files to be Secured
you can upload them outside of the public scope. For example, storage/ folder is a good place. Also, you can grab them using the file system manager. Take a look:
$image = \Storage::get('file.jpg');
Edit
A correct laravel installation just allow the content of public/ to be accesible via web browser. If other directories as storage/ or resources/ are public too, then you installation is really incorrect.
Said that, once you upload the files in storage/ folder nobody can access them except by you using the \Storage facade. When you call for example \Storage::get('file.jpg'); it returns an stream of bits that you can allocate them in a temporary folder and then display it in the webside. Once the request has finished, the image will disappear again from public domain.
No need to change the directory this can be achieved by two ways
LazyOne Answer using .htaccess
AND
Using robots.txt
I will suggest to implement both .htaccess and robots.txt as some cheap crawlers ignore robots.txt but they can't ignore .htaccess
You can follow this method
image-accessibility-for-authenticated-users-only
As this only allows authorized uses to view image

Laravel 5 template storage directory

In Laravel 4 my public directory is my template storage such as images and css,js folder, what's this storage in Laravel 5? How do I store files in new version using asset() to access them?
There are 3 folders which are relevant to your questions.
They are place in The Root Directory.
Regarding to Laravel The Root Directory documentation:
The public directory contains the front controller and your assets (images, JavaScript, CSS, etc.).
The resources directory contains your views, raw assets (LESS, SASS, CoffeeScript), and localization files.
The storage directory contains compiled Blade templates, file based sessions, file caches, and other files generated by the framework. This folder is segregated into app, framework, and logs directories. The app directory may be used to store any files utilized by your application. The framework directory is used to store framework generated files and caches. Finally, the logs directory contains your application's log files.
It is possible to create a content folder in Storage folder and share it only for members (means no available for public access), if that the case follow example link below.
To define path in your code, for public path use public_path the same for storage storage_path regarding to Laravel Paths documentation.
Finally here you find the example of storage_path usage and how you protect you files and folders from public access.
How to protect image from public view in Laravel 5?

In Laravel, what folder should I put a non-public data.json file?

I have another system that will drop in a data.json file somewhere onto my Laravel site/folder structure.
I want only Laravel to be able to be able to read the json file (i.e. a user can't see it by typing a url into a browser).
Where should this file go?
I'm currently torn between putting it in application/models folder or application/[new folder]. My webroot is set to the public folder, so you can't access the application folder via a browser.
If it is in there, I'm assuming I will be able to read it within php but not javascript (which is okay).
Just create a new folder in the app/ directory. Thats not visible to outsiders. Everything visible is in the public folder, as you said. If you create a new folder you can autoload it by setting up composer.json.

Meteor Images, CSS, "Normal" Web Serving

I've seen this question come up a lot;
How do I put images on my Meteor website?
How do I host "standard" web content with Meteor?
I tried adding a <img src="img/myimage.png"> tag but no image shows!
How can I host some files on a Meteor site?
Put the content in a folder named "public" in your project root.
You do not need to include /public in your URLs.
Any additional folder structure within public is supported.
NodeJS routing plugins are not required, as other answers have supplied.
Place external library's javascript files in /lib. They will be automatically included.
Explanation
In Meteor, you can host "standard" web content by creating a "public" directory in the root of your project. Any images, files, or data you place in this folder will be served as normal by the NodeJS server, as if they were in the root of the server.
Example
Structure within project: /public/test/img.png
Corresponding image URL: /test/img.png
Example HTML tag: <img src="/test/img.png"/>
Create a new folder public inside the project directory. Add a new folder img (or any other name of your choice) inside the public folder. Copy all the images that you require to be added in to your HTML into this folder.
Now you can use it like - <img src="img/myimage.png">
You don't need to include /public in the in the URL.

Resources