wiihas.blogg.se

Google drive api rest
Google drive api rest












google drive api rest

Public void DownloadFile(string blobId, string savePath) The DownloadFile method accept the blobId that we get back from the UploadFIle method. The SaveStream method will save the file into your web folder. Then after I upload to google drive I need to return back the blob id so that I can save to the database Bonus: if you want to display image in img tag just use it like thisįinally is the download method. We can add metdata for the file we upload using request.Fields. I’m passing in the path from the system so that we can upload to drive. I only write this method to upload image file so you can adjust acordingly to your need. Request = (fileMetadata, stream, "image/jpeg") Using (var stream = new FileStream(path, FileMode.Open)) Var fileMetadata = new 3.Data.File() įileMetadata.Name = Path.GetFileName(path) We just need to read creadential.json file then return back instance of DriverService.

google drive api rest

Var service = new DriveService(new BaseClientService.Initializer()īefore we working with Google Drive API we need to authenticate. New FileDataStore(credPath, true)).Result GoogleClientSecrets.Load(stream).Secrets, String credPath = Environment.GetFolderPath() ĬredPath = Path.Combine(credPath, "./credentials/credentials.json") Ĭredential = GoogleWebAuthorizationBroker.AuthorizeAsync( New FileStream("credentials.json", FileMode.Open, FileAccess.Read)) Private DriveService GetDriveServiceInstance() Private string Scopes = īelow is the full list of scope that Google Drive API currently support granted full control of google drive api

google drive api rest

First in the class I need to let Google Drive API know what scopes I granted for my application Put this comman inside package manager console Let get start.īefore you process please make sure you have basic concept understanding how Google Drive API work and what it can offer and follow a setup to get credentials.json file and put it into your app folderīefore we begin we need to install package. So basically I implement 2 functionality that is Upload and Download. Lately I have been working with Google Drive API to upload image for post in open source project Awesome CMS Core.














Google drive api rest