GithubHelp home page GithubHelp logo

mvkozlov / gmgoogledrive Goto Github PK

View Code? Open in Web Editor NEW
38.0 38.0 11.0 196 KB

Google Drive REST Api module for Powershell

License: MIT License

PowerShell 100.00%
google google-api google-drive googledrive powershell powershell-module rest

gmgoogledrive's Introduction

Automation of everything

gmgoogledrive's People

Contributors

elhaus avatar mvkozlov avatar nebiont avatar thomas-edvardsson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gmgoogledrive's Issues

Question about oauth sign in allowing

Hello,

Thanks for the script.

I'm trying to create a script that would be configured as a daily windows scheduled task to check some dates of backup files that get uploaded to Google Drive.

I put together a script using the readme and it prompts to sign in to google and asks to allow the user to "view and manage the files in your google drive".

Could someone help me automate this part?

Thanks,

Zach

upload files to static link

upload files to static link?
i need to upload the files in pc1 and download the files in pc2 but pc2 doesn't know the link
so can you make a static link? to upload files and download files

Set-GDriveItemContent - "name" parameter value cannot be null

Receiving the following error when using the Set-GDriveItemContent cmdlet when attempting to update an existing file, similarly getting the same error when using Add-GDriveItem which uses it as well when attempting to create a new file.

PS C:\users\test\Desktop> echo $file.FullName
C:\users\test\Desktop\Documents\test.rtsz

PS C:\users\test\Desktop> echo $idValue
1Q1v-SXVaz0s0v6UOmVqhEjcmnuj1gEJm

PS C:\users\test\Desktop> Set-GDriveItemContent -AccessToken $accessToken -InFile $file.FullName -ID $idValue -Verbose
VERBOSE: Updating File 1Q1v-SXVaz0s0v6UOmVqhEjcmnuj1gEJm
VERBOSE: URI: https://www.googleapis.com/upload/drive/v3/files/1Q1v-SXVaz0s0v6UOmVqhEjcmnuj1gEJm?supportsAllDrives=true&uploadType=r
esumable&fields=kind,id,name,mimeType,parents
VERBOSE: Metadata upload, resumable, 37193 bytes, application/octet-stream
VERBOSE: Performing the operation "Uploading file from [C:\users\test\Desktop\Documents\test.rtsz]" on target "1Q1v-SX
Vaz0s0v6UOmVqhEjcmnuj1gEJm".
VERBOSE: PATCH https://www.googleapis.com/upload/drive/v3/files/1Q1v-SXVaz0s0v6UOmVqhEjcmnuj1gEJm?supportsAllDrives=true&uploadType=
resumable&fields=kind,id,name,mimeType,parents with -1-byte payload
VERBOSE: received 0-byte response of content type text/plain; charset=utf-8,application/json; charset=UTF-8

Set-GDriveItemContent : System.ArgumentNullException: Value cannot be null.
Parameter name: name
   at System.Globalization.EncodingTable.GetCodePageFromName(String name)
   at System.Text.Encoding.GetEncoding(String name)
   at Microsoft.PowerShell.Commands.ContentHelper.GetEncodingOrDefault(String characterSet)
   at Microsoft.PowerShell.Commands.BasicHtmlWebResponseObject.InitializeContent()
   at Microsoft.PowerShell.Commands.WebResponseObjectFactory.GetResponseObject(WebResponse response, Stream responseStream, 
ExecutionContext executionContext, Boolean useBasicParsing)
   at Microsoft.PowerShell.Commands.InvokeWebRequestCommand.ProcessResponse(WebResponse response)
   at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()
   at System.Management.Automation.CommandProcessor.ProcessRecord()
At line:1 char:1
+ Set-GDriveItemContent -AccessToken $accessToken -InFile $file.FullNam ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Set-GDriveItemContent

(1.0.4.2) Endless PUT do-loop in Set-GDriveItemContent for files > 4MB

Uploading a file pf3910287872.tmp with 5144978 bytes results in an endless loop.
Inspecting the code of I see 2 times: $UploadedSize = ([long]$matches[2]) + 1
Could it be that $matches is missing in the code?

VERBOSE: URI: https://www.googleapis.com/drive/v3/files/
VERBOSE: URI: https://www.googleapis.com/drive/v3/files/?supportsAllDrives=true&pageSize=100&q=name
VERBOSE: URI: https://www.googleapis.com/upload/drive/v3/files/?supportsAllDrives=true&uploadType=r
VERBOSE: Metadata upload, resumable, 5144978 bytes, application/octet-stream
VERBOSE: Performing the operation "Uploading file named 'pf3910287872.tmp' from [d:\Temp\pf39102878
VERBOSE: POST https://www.googleapis.com/upload/drive/v3/files/?supportsAllDrives=true&uploadType=r
VERBOSE: received 0-byte response of content type text/plain; charset=utf-8
VERBOSE: ResumeID: ADPycdsBKYRQlfKVLLT2N-eS-Oe-Gpka8--qkjaPZgRpJm2Q-au7T6hHj2mssnH2X4KpPrxADwypmxbC
VERBOSE: Received Range:
VERBOSE: Performing the operation "Uploading file named 'pf3910287872.tmp' from [d:\Temp\pf39102878
VERBOSE: Multiple requests upload
VERBOSE: Content-Length: 4194304, Content-Range bytes 0-4194303/5144978, readed: 4194304
VERBOSE: PUT https://www.googleapis.com/upload/drive/v3/files/?supportsAllDrives=true&uploadType=re
VERBOSE: received 0-byte response of content type text/plain; charset=utf-8
VERBOSE: Received Range: bytes=0-4194303
VERBOSE: Stream Position: 4194304, UploadedSize:4194304
VERBOSE: Content-Length: 950674, Content-Range bytes 4194304-5144977/5144978, readed: 950674
VERBOSE: PUT https://www.googleapis.com/upload/drive/v3/files/?supportsAllDrives=true&uploadType=re
VERBOSE: received 0-byte response of content type text/plain; charset=utf-8
VERBOSE: Received Range: bytes=0-4194303
VERBOSE: Stream Position: 5144978, UploadedSize:4194304
VERBOSE: Fast Forward to:4194304
VERBOSE: Content-Length: 950674, Content-Range bytes 4194304-5144977/5144978, readed: 950674
VERBOSE: PUT https://www.googleapis.com/upload/drive/v3/files/?supportsAllDrives=true&uploadType=re
VERBOSE: received 0-byte response of content type text/plain; charset=utf-8
VERBOSE: Received Range: bytes=0-4194303
VERBOSE: Stream Position: 5144978, UploadedSize:4194304
VERBOSE: Fast Forward to:4194304
VERBOSE: Content-Length: 950674, Content-Range bytes 4194304-5144977/5144978, readed: 950674
VERBOSE: PUT https://www.googleapis.com/upload/drive/v3/files/?supportsAllDrives=true&uploadType=re
VERBOSE: received 0-byte response of content type text/plain; charset=utf-8
VERBOSE: Received Range: bytes=0-4194303
VERBOSE: Stream Position: 5144978, UploadedSize:4194304
VERBOSE: Fast Forward to:4194304
VERBOSE: Content-Length: 950674, Content-Range bytes 4194304-5144977/5144978, readed: 950674
VERBOSE: PUT https://www.googleapis.com/upload/drive/v3/files/?supportsAllDrives=true&uploadType=re
etc. etc

Cyrillic characters in the source filename

Good time of day!
First of all, sorry for my english.

When I upload / create an item on GDrive from a source file / directory with a name containing Cyrillic characters, the target item name on GDrive contains unreadable characters.

My environment
Windows 8.1/10 PRO RU
$PSVersionTable:

Name                           Value                                                                                                                                                          
----                           -----                                                                                                                                                          
PSVersion                      5.1.17763.1490                                                                                                                                                 
PSEdition                      Desktop                                                                                                                                                        
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                        
BuildVersion                   10.0.17763.1490                                                                                                                                                
CLRVersion                     4.0.30319.42000                                                                                                                                                
WSManStackVersion              3.0                                                                                                                                                            
PSRemotingProtocolVersion      2.3                                                                                                                                                            
SerializationVersion           1.1.0.1                                                                                                                                                        

$OutputEncoding

IsSingleByte      : True
BodyName          : koi8-r
EncodingName      : Кириллица (Windows)
HeaderName        : windows-1251
WebName           : windows-1251
WindowsCodePage   : 1251
IsBrowserDisplay  : True
IsBrowserSave     : True
IsMailNewsDisplay : True
IsMailNewsSave    : True
EncoderFallback   : System.Text.InternalEncoderBestFitFallback
DecoderFallback   : System.Text.InternalDecoderBestFitFallback
IsReadOnly        : True
CodePage          : 1251

How to import this module?

Sorry for the stupid question, I just started learning powershell right now.

I've read the README file but haven't found how to import it into my scripts.
How can I do that?

Issue with Authorization Code

Select-Object : Property "forms" cannot be found.
At C:\Development Tools\GMGoogleDrive\GMGoogleDrive\Public\Request-GDriveAuthorizationCode.ps1:106 char:37

  • ... $forms = $ie.Document | Select-Object -ExpandProperty forms
  •                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidArgument: (System.__ComObject:PSObject) [Select-Object], PSArgumentException
    • FullyQualifiedErrorId : ExpandPropertyNotFound,Microsoft.PowerShell.Commands.SelectObjectCommand

Request-GDriveAuthorizationCode : You cannot call a method on a null-valued expression.
At line:1 char:12

  • $code = Request-GDriveAuthorizationCode -ClientID $oauth_json.web. ...
  •        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
    • FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Request-GDriveAuthorizationCode

I scoped out the module you wrote for this, is there a way to automate this for public access ? or is this strictly meant for manual use? I like the idea, it just seems a little short on automation details... Given all the hard work you apparently put into this... seems like it should be possible to automate

Can't upload files larger than 2GB

This is the error thrown when uploading files over 2GB:

Set-GDriveItemContent : System.Management.Automation.MethodException: Cannot convert argument "val2", with value: "7325106436", for "Min" to type "System.Int32": "Cannot convert value "7325106436" to type "System.Int32". Error: "Value was either too large or too
small for an Int32."" ---> System.Management.Automation.PSInvalidCastException: Cannot convert value "7325106436" to type "System.Int32". Error: "Value was either too large or too small for an Int32." ---> System.OverflowException: Value was either too large or too
small for an Int32.
at System.Convert.ToInt32(Int64 value)
at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
at System.Management.Automation.LanguagePrimitives.ConvertNumeric(Object valueToConvert, Type resultType, Boolean recursion, PSObject originalValueToConvert, IFormatProvider formatProvider, TypeTable backupTable)
--- End of inner exception stack trace ---
at System.Management.Automation.LanguagePrimitives.ConvertNumeric(Object valueToConvert, Type resultType, Boolean recursion, PSObject originalValueToConvert, IFormatProvider formatProvider, TypeTable backupTable)
at CallSite.Target(Closure , CallSite , Type , Object , Object )
--- End of inner exception stack trace ---
at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
at Set-GDriveItemContent(Closure , FunctionContext )
At C:\windows\system32\windowspowershell\v1.0\Modules\GMGoogleDrive-master\GMGoogleDrive\Public\Add-GDriveItem.ps1:97 char:5

  • Set-GDriveItemContent @PSBoundParameters
    
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
    • FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Set-GDriveItemContent

Pipeline support in upload fuinctions

Continuation of discussion with @mcc85s in #6

mean it actually uploaded most of my files that way, but I think it has the same general error that 7z has when you try to pipeline a folder structure, if the folders are duplicated ( since multiple files in a folder would mean that... ) then it just errors out.

Your upload method does not allow to determine parent of each file.
look into this:
if cmdlet can support pipeline and you pass this file list

D:\toUoload\file1
D:\ToUpload\file2
D:\ToUpload2\file3
C:\WorkItems\ToUpload3\SomeDirectory\file4

what root folder should be for each file in this list ?
How cmdlet should determine it ?
If it uploaded all files into one folder I think this wouldn't what you want

But if I support pipeline input this question will be raised

I can aggregate all files in PROCESS{} block and do uploading in END {} , trying to determine common root... but this break all the pipeline idea :)

May be just use new Add-GDriveFolder ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.