Skip to content
Merged
Show file tree
Hide file tree
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 Mar 24, 2026
8d3142d
updated End of Life
rdonovan92 Mar 24, 2026
668a9ea
added publishtogallery workflow
rdonovan92 Mar 24, 2026
be6377a
end of file line
rdonovan92 Mar 24, 2026
1c70f1c
updated psd1
rdonovan92 Mar 24, 2026
5373ec5
psd1 fixes
rdonovan92 Mar 24, 2026
4693896
Fixed heading in Readme
rdonovan92 Mar 25, 2026
08db6e5
README header fix
rdonovan92 Mar 25, 2026
7a34679
PublishToGallery Workflow
rdonovan92 Mar 25, 2026
5223038
Merge remote-tracking branch 'origin/main' into PublishToGallery
rdonovan92 Mar 25, 2026
264a5bf
end of line
rdonovan92 Mar 25, 2026
b5677f8
updated checkout version
rdonovan92 Mar 25, 2026
bd39544
Fixed function language in README
rdonovan92 Mar 25, 2026
984238a
Changelog
rdonovan92 Mar 25, 2026
4b96a55
Added 3 new functions for collaboration management
rdonovan92 Mar 31, 2026
7f3af2a
updated blank spacing
rdonovan92 Mar 31, 2026
7cd9393
Merge branch 'main' into Collaboration-Functions-Added
rdonovan92 Mar 31, 2026
c71d175
Update Module Version Number
rdonovan92 Apr 1, 2026
f786367
Casing fixes
rdonovan92 Apr 1, 2026
084849c
Upgrades and fixes
rdonovan92 Apr 2, 2026
1cf1642
description update
rdonovan92 Apr 2, 2026
dc35bea
trailing space
rdonovan92 Apr 2, 2026
1e3ba5d
Version Updated for release
rdonovan92 Apr 3, 2026
d41d292
Merge remote-tracking branch 'origin/main' into Send-File-Function-Up…
rdonovan92 Apr 3, 2026
4ece1ec
blank space trailing
rdonovan92 Apr 3, 2026
6428231
Changelog fixes
rdonovan92 Apr 7, 2026
7474524
Apply suggestions from code review
rdonovan92 Apr 7, 2026
346e9f1
Update CHANGELOG.md
rdonovan92 Apr 7, 2026
e0bc6f8
Merge branch 'SendFileupdates' of github.com:techservicesillinois/Sec…
rdonovan92 Apr 7, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Removed

## [0.0.5] - 2026-04-03
Comment thread
rdonovan92 marked this conversation as resolved.

### Changed
- Updated Send-BoxFile Function to have the ability to send files from memory.
- Updated Invoke-BoxRestCall to support Form Settings

## [0.0.4] - 2026-03-31

- Added the following functions; Get-BoxCollaboration, Set-Box Collaboration, Remove-BoxCollaboration.
Expand Down
2 changes: 1 addition & 1 deletion src/UofIBox/UofIBox.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
RootModule = 'UofIBox.psm1'

# Version number of this module.
ModuleVersion = '1.0.1'
ModuleVersion = '1.0.2'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
1 change: 1 addition & 0 deletions src/UofIBox/UofIBox.psm1
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
$Script:Settings = Get-Content -Path "$PSScriptRoot\settings.json" | ConvertFrom-Json
$Script:BoxSession = $NULL
[int]$Script:APICallCount = 0

Expand Down
Empty file removed src/UofIBox/dscresources/.gitkeep
Empty file.
17 changes: 14 additions & 3 deletions src/UofIBox/functions/public/Invoke-BoxRestCall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ Hashtable body that will be converted to JSON.
.PARAMETER Upload
Switch indicating the upload API endpoint should be used.

.PARAMETER Form
Hashtable of form fields for multipart form data requests.

.EXAMPLE
Invoke-BoxRestCall -RelativeURI "folders/123" -Method GET

Expand All @@ -38,6 +41,8 @@ function Invoke-BoxRestCall {

[hashtable]$Body,

[hashtable]$Form,

[switch]$Upload
)

Expand All @@ -52,10 +57,12 @@ function Invoke-BoxRestCall {
}

if ($Upload) {
$BaseURI = "https://upload.box.com/api/2.0/"
$BaseURI = "$($Script:Settings.UploadBaseURI)"
$contentType = "multipart/form-data"
}
else {
$BaseURI = "https://api.box.com/2.0/"
$BaseURI = "$($Script:Settings.BaseURI)"
$contentType = "application/json"
}
}

Expand All @@ -64,7 +71,7 @@ function Invoke-BoxRestCall {
$IVRSplat = @{
Headers = @{
Authorization = "Bearer $($Script:BoxSession.AccessToken)"
"Content-Type" = "application/json"
"Content-Type" = $contentType
}
Method = $Method
Uri = "$BaseURI$RelativeURI"
Expand All @@ -74,6 +81,10 @@ function Invoke-BoxRestCall {
$IVRSplat.Add("Body", ($Body | ConvertTo-Json -Depth 10))
}

if ($Form) {
$IVRSplat.Add("Form", $Form)
}

Write-Verbose "Calling Box API: $Method $RelativeURI"

try {
Expand Down
103 changes: 83 additions & 20 deletions src/UofIBox/functions/public/Send-BoxFile.ps1
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
}
4 changes: 4 additions & 0 deletions src/UofIBox/settings.json
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/"]
}