How to upload file to OneDrive using laravel - laravel

I am a beginner with Laravel. I'm tasked with uploading files to OneDrive, but I don't know of any way to upload files. Anyone has an idea.
I tried searching GG and got some ways but I still don't get it. Can anyone give me any other ideas?

You can use the Microsoft Graph API to upload files to OneDrive from a Laravel application. Here's a general outline of the steps:
Register your application with Microsoft Azure to obtain a client ID and client secret.
Install the 'microsoft/microsoft-graph' package using Composer.
Obtain an access token for the Microsoft Graph API using your client ID and client secret.
Use the 'Graph' class to create a new 'DriveItem' object representing the file you want to upload, and set its contents.
Use the 'DriveItem' object's 'createUploadSession()' method to obtain an upload session URL.
Use Laravel's 'Illuminate\Http\UploadedFile' class to read the file contents and send a 'PUT' request to the upload session URL, using the 'X-Upload-Content-Length' and 'Content-Range' headers to specify the size and location of the uploaded data.
FOR MORE DETAILS: How to upload file to OneDrive using Laravel ?

Related

Best approach to download files from Azure Blob Storage using file urls

What is the best approach for the following requirement: I have files stored in Azure Blob Storage with a Private endpoint. I need to show to the user, a table with a column containing these file URLs in the browser. When a user clicks on the link, it should either open the file in a new tab or download the file.
I could show the URLs and download files using the Power BI report when the Blob Storage has public access. But in my scenario, it's a Private endpoint. I tried appending the SAS token to the URL, and that also worked, but in this case, SAS token is visible in the browser which is not allowed in my case. So this also does not work for my scenario.
Can we achieve this using Power BI or Power Apps or any other tools/api?
Could you please suggest the steps?
Thanks
I tried in my environment and got below results:
If you need download blob through browser with private container, you need Blob URL + SAS token because it provides read and writes to access blobs.
If you are using public container, you can download with Blob URL through browser.
There is no option to call your Blob URL by hiding SAS token.
As workaround, if you need to hide the SAS token from the user and try to access the blob, you can make use of Power Automate connector here:
I have connected to my Azure blob storage with these Power Automate connectors. 1) I have first connected to my Blob URL endpoint> And created a SAS URI with this connector.
The SAS URI is created successfully by the connector, and I have saved the SAS token inside the compose variable for it to be hidden.
Later I call an HTTP trigger to trigger the SAS token and get the Image content as HTTP body in the output.
When I decode the HTTP body content> I get my Blob Image successfully.
You can convert base64 to image you can use this link:
If you want your users to access this Blob, you can further convert this b64 encoded string into Image and save the file in OneDrive, SharePoint for your users to access you can refer this link by eric-cheng.
If you want to Email your users the Blob file, that can also be done by using Outlook, Gmail, etc connectors later.

Storing and Retrieving Uploaded File with Laravel and Vue JS

I am currently working on a Vue JS + Vuetify + Axios + Laravel architecture where I am making a dashboard. Currently I am working on the user profile where they can upload a picture for their avatar but also can upload their business licence (via a different uploader).
User need to be able to modify update those documents later on.
What is the best strategy to implement this requirement nicely and with proper security ?
Store the files in a private area of Laravel or a public one after renaming it with a random + user name?
Store the file as a blob in mysql directly and retrieving ?
Store the path of the file in mysql only while storing the file in a public/private folder under Laravel tree ?
For authentication I plan to use jwt and websanova.
Where you store the avatar depends on where it needs to be displayed. Will it be shown only to that user? Other logged in users? Non-authenticated users?
Regarding the user's business licence, I would store that in a folder that's not publicly accessible and access it via an API endpoint. This way you can implement the necessary security rules via your Laravel controller.
Generally speaking, I'd avoid storing files in a DB. You're bloating the size of the DB, which impacts on doing backups/restores, among other things. Having files stored on the file system also makes it easier to move to cloud storage (such as Amazon S3) at some point, if you need to scale your app.

Google API Private access

I want to create an app that only my family members will be using. It needs to access Google Drive files using oauth access (to be precise it will be PHP client).
I've set permissions in Google API Console ./auth/drive.readonly.
I realize that I'll get an unverified app warning, but anyway, when I try to access the resources I get 403 error. Also when accessing for the first time and pasting the URL to get verification code it only says that app will have access to metadata, which is default permission.
Is it possible at all to create this kind of unverified app that will have those "unsafe" access to drive?
If anyone faces the same problem - when requesting access through an API, be it REST or PHP library one needs to specify the permissions app will be using. Those need to match the ones specified in Google Dev Console.

Files stored in AWS bucket to only be downloaded if users are logged into Laravel app. Not by directly going to URL

I only want users to be able to download files which are saved in my AWS bucket if they are logged into my Laravel app. I do not want users to be able to download the files if they are not logged into the system and not by directly going to the URL. Can someone please help me achieve this? I think I may need to somehow set the document as private but I'm not sure about this.
There are two options that I know of:
Returning a temporary signed URL which the user can use to download the file directly from S3.
Streaming or downloading the file from S3 through your application.
For the first option you can use the Storage facade's temporaryUrl method like this to allow access for 5 minutes:
$url = Storage::disk('s3')->temporaryUrl(
'file.jpg', now()->addMinutes(5)
);
To download the file through your server you could return:
return Storage::download('file.jpg');
Don't quote me on the following, but I think the advantage of using the S3 temporary url is that the download doesn't have to happen through your server which frees up your server for other requests. The benefit of downloading through your server is that you would be able to authenticate against every request and there won't be a temporary url which a user would be able to share.

Authenticating PDF streaming via Laravel API

I have a Laravel API that generates a pdf. I am using laravel passport for the pdf. I want to stream the pdf in the browser not download it. I currently generate a pdf but it is open to the world, anybody would be able to to access the pdf. I want to add authentication for it. A user should be able to see his/her pdfs generated by my app and not any other user's pdfs.
My idea so far is to generate a personal access token for the user and pass it via the url.
Is this a good idea? Any other ideas I should consider on how to accomplish this?
Use laravel authentication to stop unauthorized access to routes, here is the documentation how you can do that,
https://laravel.com/docs/5.6/authentication

Resources