AtlassianPS / ConfluencePS

Confluence REST API (including Cloud) via PowerShell
https://AtlassianPS.org/module/ConfluencePS
MIT License
149 stars 42 forks source link

Add-ConfluenceAttachment hangs on files over 2MB #170

Open jobafett2012 opened 5 years ago

jobafett2012 commented 5 years ago

When attempting to upload any files larger than 2MB (2-7MB in our case) to a page in our Confluence space, powershell's memory usage on the client machine doing the uploading spikes to 2-3GB and the upload never completes. We can upload files less than 2MB quickly and without issue, and we have confirmed with our Atlassian team that the max file size for REST API uploads is 10MB. We are on the latest version of AtlassianPS and our server is on Confluence version 6.13.4

lipkau commented 5 years ago

I am sorry, but I couldn't reproduce your problem. I tried 3 different files, as you will see below:

Add-ConfluenceAttachment -PageID $page.id -FilePath $largeFile
ID        : 265846790
Status    : current
Title     : latest_usb_driver_windows.zip
Filename  : 215187457_latest_usb_driver_windows.zip
MediaType : application/zip
FileSize  : 8682859
Comment   : 
SpaceKey  : RD
PageID    : 215187457
Version   : 1
URL       : https://powershell.atlassian.net/wiki/download/attachments/215187457/latest_usb_driver_windows.zip?version=1&modificationDate=1559655792966&cacheVersion=1&api=v2
Get-ConfluenceAttachment -PageID $page.id | select title,filesize      
Title                         FileSize
-----                         --------
latest_usb_driver_windows.zip  8682859
LexaPrinterOne_1.10.bin        1036736
favicon_package_v0.16.zip        54456

what version of the module are you using? what version of confluence are you using?

jobafett2012 commented 5 years ago

Confluence Version: 6.13.4 AtlassianPS/ConfluencePS Version: 2.5

JoshCrook commented 5 years ago

I did some testing and for every 1MB your uploaded file is, the PowerShell process' memory usage increases by ~1,600MB.

Confluence Cloud 1000.0.0-52f4e0df752 ConfluencePS Version: 2.5

ConfluencePS_i170_tests.txt

jobafett2012 commented 4 years ago

I did some testing and for every 1MB your uploaded file is, the PowerShell process' memory usage increases by ~1,600MB.

Confluence Cloud 1000.0.0-52f4e0df752 ConfluencePS Version: 2.5

ConfluencePS_i170_tests.txt

This is pretty similar to the behavior we experience. I assume there hasn't been any progress on finding and possibly correcting this?

lipkau commented 4 years ago

Sorry, no. I didn't have had time to look into this yet

spudsrus commented 4 years ago

Also seeing this on: Confluence 6.10.1 ConfluencePS 2.5

spudsrus commented 4 years ago

Not sure if the issue is with the module or the confluence rest API. I've been able to work around the issue by using a webclient upload method that I guessed would work from seeing it on a jira thread.

$Headers = @{"Authorization" = "Basic "+[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(($credential.UserName+":"+[System.Runtime.InteropServices.marshal]::PtrToStringAuto([System.Runtime.InteropServices.marshal]::SecureStringToBSTR($credential.Password)) )))} 

$wc = new-object System.Net.WebClient
$wc.Headers.Add("Authorization", $headers.Authorization)
$wc.Headers.Add("X-Atlassian-Token", "nocheck") 
$wc.UploadFile("<site>/rest/api/content/<pageid>/child/attachment/", $filepath)
SamWalkerRxSense commented 4 years ago

I have this same issue. spudrus's workaround works for me.

ConfluencePS 2.5 PSVersion 5.1.18362.145

Name : Visual Studio Code Host Version : 2019.9.0

Confluence Cloud Confluence 1000.0.0