-
Notifications
You must be signed in to change notification settings - Fork 0
Send fileupdates #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
101f973
Removed Borg template and updated LICENSE per SecDev advisement
rdonovan92 8d3142d
updated End of Life
rdonovan92 668a9ea
added publishtogallery workflow
rdonovan92 be6377a
end of file line
rdonovan92 1c70f1c
updated psd1
rdonovan92 5373ec5
psd1 fixes
rdonovan92 4693896
Fixed heading in Readme
rdonovan92 08db6e5
README header fix
rdonovan92 7a34679
PublishToGallery Workflow
rdonovan92 5223038
Merge remote-tracking branch 'origin/main' into PublishToGallery
rdonovan92 264a5bf
end of line
rdonovan92 b5677f8
updated checkout version
rdonovan92 bd39544
Fixed function language in README
rdonovan92 984238a
Changelog
rdonovan92 4b96a55
Added 3 new functions for collaboration management
rdonovan92 7f3af2a
updated blank spacing
rdonovan92 7cd9393
Merge branch 'main' into Collaboration-Functions-Added
rdonovan92 c71d175
Update Module Version Number
rdonovan92 f786367
Casing fixes
rdonovan92 084849c
Upgrades and fixes
rdonovan92 1cf1642
description update
rdonovan92 dc35bea
trailing space
rdonovan92 1e3ba5d
Version Updated for release
rdonovan92 d41d292
Merge remote-tracking branch 'origin/main' into Send-File-Function-Up…
rdonovan92 4ece1ec
blank space trailing
rdonovan92 6428231
Changelog fixes
rdonovan92 7474524
Apply suggestions from code review
rdonovan92 346e9f1
Update CHANGELOG.md
rdonovan92 e0bc6f8
Merge branch 'SendFileupdates' of github.com:techservicesillinois/Sec…
rdonovan92 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,54 +1,117 @@ | ||
| <# | ||
| .SYNOPSIS | ||
| Uploads a file to Box. | ||
| Uploads a file to Box from a local path or from memory. | ||
|
|
||
| .DESCRIPTION | ||
| Uploads a local file to a specified Box folder. | ||
| Uploads a file to a specified Box folder. You can upload a file directly from a local path | ||
| or from an in-memory byte array, which is useful for generating files on the fly | ||
| without writing to disk. | ||
|
|
||
| .PARAMETER FilePath | ||
| Local path of the file to upload. | ||
| (Local path upload) The path of the file on the local filesystem to upload. | ||
| Required when uploading from a file. | ||
|
|
||
| .PARAMETER FileBytes | ||
| (In-memory upload) The file content as a byte array. Required when uploading from memory. | ||
|
|
||
| .PARAMETER FileName | ||
| (In-memory upload) The name to give the file in Box. Required when using FileBytes. | ||
|
|
||
| .PARAMETER ParentFolderId | ||
| Box folder ID where the file will be uploaded. | ||
| The Box folder ID where the file should be uploaded. | ||
|
|
||
| .EXAMPLE | ||
| # Upload a local file | ||
| Send-BoxFile -FilePath "C:\Temp\report.pdf" -ParentFolderId "123456" | ||
|
|
||
| .EXAMPLE | ||
| # Upload a CSV from memory | ||
| $csv = $data | ConvertTo-Csv -NoTypeInformation | ||
| $bytes = [System.Text.Encoding]::UTF8.GetBytes($csv -join "`n") | ||
| Send-BoxFile -FileBytes $bytes -FileName "report.csv" -ParentFolderId "123456" | ||
| #> | ||
|
|
||
| function Send-BoxFile { | ||
|
|
||
| [CmdletBinding()] | ||
| [CmdletBinding(DefaultParameterSetName = "FromPath")] | ||
| param( | ||
| [Parameter(Mandatory)] | ||
| # --- File Path Upload --- | ||
| [Parameter(Mandatory, ParameterSetName = "FromPath")] | ||
| [string]$FilePath, | ||
|
|
||
| # --- In-Memory Upload --- | ||
| [Parameter(Mandatory, ParameterSetName = "FromMemory")] | ||
| [byte[]]$FileBytes, | ||
|
|
||
| [Parameter(Mandatory, ParameterSetName = "FromMemory")] | ||
| [string]$FileName, | ||
|
|
||
| # --- Shared --- | ||
| [Parameter(Mandatory)] | ||
| [string]$ParentFolderId | ||
| ) | ||
|
|
||
| if ($null -eq $Script:BoxSession) { | ||
| throw "No Box session established. Run New-BoxSession first." | ||
| switch ($PSCmdlet.ParameterSetName) { | ||
|
|
||
| "FromPath" { | ||
| if (-not (Test-Path -Path $FilePath -PathType Leaf)) { | ||
| throw "File not found at path: $FilePath" | ||
| } | ||
|
|
||
| $FileBytes = [System.IO.File]::ReadAllBytes($FilePath) | ||
| $FileName = [System.IO.Path]::GetFileName($FilePath) | ||
| } | ||
|
|
||
| "FromMemory" { | ||
| } | ||
| } | ||
|
|
||
| $Attributes = @{ | ||
| name = [System.IO.Path]::GetFileName($FilePath) | ||
| name = $FileName | ||
| parent = @{ | ||
| id = $ParentFolderId | ||
| } | ||
| } | ConvertTo-Json -Compress | ||
|
|
||
| $Headers = @{ | ||
| Authorization = "Bearer $($Script:BoxSession.AccessToken)" | ||
| } | ||
| # --- Build multipart form body --- | ||
| $boundary = [System.Guid]::NewGuid().ToString() | ||
| $LF = "`r`n" | ||
|
|
||
| $memStream = New-Object System.IO.MemoryStream | ||
| $writer = New-Object System.IO.StreamWriter($memStream) | ||
|
|
||
| # --- attributes part --- | ||
| $writer.Write("--$boundary$LF") | ||
| $writer.Write("Content-Disposition: form-data; name=`"attributes`"$LF") | ||
| $writer.Write("Content-Type: application/json$LF$LF") | ||
| $writer.Write($Attributes + $LF) | ||
|
|
||
| $Form = @{ | ||
| attributes = $Attributes | ||
| file = Get-Item $FilePath | ||
| # --- file part --- | ||
| $writer.Write("--$boundary$LF") | ||
| $writer.Write("Content-Disposition: form-data; name=`"file`"; filename=`"$FileName`"$LF") | ||
| $writer.Write("Content-Type: application/octet-stream$LF$LF") | ||
| $writer.Flush() | ||
|
|
||
| # Write raw file bytes | ||
| $memStream.Write($FileBytes, 0, $FileBytes.Length) | ||
|
|
||
| # --- closing boundary --- | ||
| $writer.Write("$LF--$boundary--$LF") | ||
| $writer.Flush() | ||
|
|
||
| $bodyBytes = $memStream.ToArray() | ||
| $memStream.Close() | ||
|
|
||
| # --- Invoke API --- | ||
| $IVRSplat = @{ | ||
| Uri = "$($Script:Settings.UploadBaseURI)files/content" | ||
| Method = "POST" | ||
| Headers = @{ | ||
| Authorization = "Bearer $($Script:BoxSession.AccessToken)" | ||
| "Content-Type" = "multipart/form-data; boundary=$boundary" | ||
| } | ||
| Body = $bodyBytes | ||
| } | ||
|
|
||
| Invoke-RestMethod ` | ||
| -Method POST ` | ||
| -Uri "$($Script:Settings.UploadBaseURI)files/content" ` | ||
| -Headers $Headers ` | ||
| -Form $Form | ||
| Invoke-RestMethod @IVRSplat | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "BaseURI": ["https://api.box.com/2.0/"], | ||
| "UploadBaseURI": ["https://upload.box.com/api/2.0/"] | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.