Laravel Filesystem: Managing Folders in Google Drive API - laravel

I am following this tutorial:-
https://gist.github.com/sergomet/f234cc7a8351352170eb547cccd65011
My Laravel application requires files to be organized inside a folder. So, whenever a file is uploaded it should be saved inside a folder that it belongs to.
Before uploading a file, I must check whether the folder exists or not. In Laravel, I have used this method to list all the directories at root.
$directories = Storage::directories();
However, it returns a list of alphanumeric unique ids with no references to the human readable names. I don't want to create duplicate folder even though it is possible in Google drive.
So, how do we get list of folder names along with reference id?

The proper way you should create a lookup table and store the id and folder names. Otherwise if you are querying the folder name you will need to fetch the meta data by id:
$metadata = Storage::disk('gdrive')->getAdapter()->getMetadata($folderId);
The metadata format can be check here. You may notice that Google Drive is ID based filesystem, so this connector need ID based path.

Related

Laravel storage, should I organize my files on database?

I have a web app where the user can upload files, create folders and stuff like that, I upload it on Google Cloud Storage, and organize it on a table files on my database, where I save the file name, path, size, extension, name, etc
But now I have a problem, if I rename a folder, I have to update multiples files on my database, update the folder and all the children, on storage I have to move each file to a new directory and delete all the content of the old directory
It seens to be too much just for a rename, I think the correct way to deal with the file manager should be just retriving the files directly from the storage and get over my database table
That is my question, should I get over my files table?

Laravel - where to store files which I don't want to share with users

For example, I want to merge two .png files in one .png file, but I don't want to share those parts with user. Currently I am storing files in storage folder, but the problem is that storage folder is with .gitignore file as default. Of course I could allow to push it to git, but I suppose it's not a good idea, because there could be thousands of another files uploaded by the user. Now if I want to continue work from another computer I should move all my parts manually.
So what you could advice to me?
You can store it anywhere you want in your application.
For example, you can make a folder in your projects root called /uploads and then use one of laravel helper functions to specify where to save the file:
Example:
$save_path = base_path('uploads');
You can use the Laravel File Class to make sure the path exists with:
File::makeDirectory($save_path, $mode = 0755, true, true);
You will need to add use File; in the top of the file with all the class includes.
Later, to access said files you can make a View Composer which you can add logic to in order to limit who can view the file.
If you want to protect your files so that nobody can access without permission store all file into storage folder. Don't put your file in public folder.

Does Laravel have a convention for a local permanent uploaded file storage location?

I have some forms that allow the user to upload files that only they can view so I will have to store them somewhere. However, I haven't been able to find any information about where these files would usually be stored if I want them to be kept on the local server. Therefore I have to assume that there is no convention for the permanent storage location of uploaded files. Am I correct in this assumption?
To be clear, I'm not talking about temporary storage locations.
Additionally, would it be a bad idea to have the storage location of all the files as a subfolder of the app directory (with gitignore enabled on it)? Or would it be a better idea to have it outside of the app folder? Thanks!
There is no explicit convention on where to store user uploaded files.
However Laravel ships with a storage directory where it stores framework related data such as cache, sessions, etc. As the name denotes it's a good place to store files, not just framework files. Also the Laravel Filesystem Documentation mentions that the default configured location is storage/app (but that can be changed to fit your needs):
When using the local driver, note that all file operations are relative to the root directory defined in your configuration file. By default, this value is set to the storage/app directory. Therefore, the following method would store a file in storage/app/file.txt: Storage::disk('local')->put('file.txt', 'Contents');
This storage/app folder will by default be ignored by Git.
If you also need the files to be publicly available, then you have two options:
1. Store them somewhere in the public directory.
2. Store them in the storage directory as suggested above and create a symbolic link to the folder from a public location. On Linux you can run this:
ln -s /path/to/laravel/public/files /path/to/laravel/storage/app/files
Of course the directory names can be whatever you like, I used files as an example.
The first option is for cases where you don't have shell access or are otherwise unable to create symbolic links. So if possible I suggest you use the second option.
Laravel uploads to the temporary file path, then you will have to move the file:
$request->file('photo')->move($destinationPath);
This method will move the file from its temporary upload location (as determined by your PHP configuration) to a more permanent destination of your choosing.
SOURCE: https://laravel.com/docs/master/requests#files

How to source images from my storage to NetSuite without uploading them to the file cabinet?

In order to place images in the web store, they have to be uploaded to the file cabinet and then the file name needs to be associated with the item.
What I am looking to do, is to source the images from my current internal storage to NetSuite and still be able to view the images on the website. I am trying to find a way to do this because I don't want to have to upload them all individually or with a mass upload.
You will need to create a custom item field of type "text" and associate the field to the item record.
You can then place the full path to your image in the field you just created and reference the custom field in your templates.
This will allow you to use urls from your own host, but dynamically be able to use them within the NetSuite web store.

Why does Magento create batch_xx.tmp file in var/tmp folder

Why does Magento create batch_xx.tmp file in var/tmp folder. This file actually contains list of customers with full email address. To comply with certain regularity issues, we can not store customer information in plain file but, this is creating problem
That is a temporary file created by the dataflow export process. Specifically in app/code/core/Mage/Dataflow/Model/Batch/Io.php.

Resources