Skip to content
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

Error thrown when POST-ing large payload #30

Open
Windos opened this issue Mar 3, 2019 · 7 comments
Open

Error thrown when POST-ing large payload #30

Windos opened this issue Mar 3, 2019 · 7 comments

Comments

@Windos
Copy link

Windos commented Mar 3, 2019

I'm trying to use Send-TwitterAccount_UpdateProfileBanner to update my account banner:

$Image = [Convert]::ToBase64String((Get-Content .\TwitterBanner.png -Encoding Byte))
Send-TwitterAccount_UpdateProfileBanner -banner $Image

Naturally, that Image string is HUGE, as I'm trying to send a 1500x500 image (the recommended size for one of these banners) that's 101 KB on disk.

When run, I get back

Get-OAuthParameters : Exception calling "EscapeDataString" with "1" argument(s): "Invalid URI: The Uri string is too long."
At C:\Users\joshuak\Documents\WindowsPowerShell\Modules\PSTwitterAPI\0.0.7\public\Invoke-TwitterAPI.ps1:26 char:24
+     $OAuthParameters = Get-OAuthParameters @OAuthParameters_Params
+                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Get-OAuthParameters
 
Invoke-RestMethod : Cannot bind parameter 'Method' to the target. Exception setting "Method": "Cannot convert null to type "Microsoft.PowerShell.Commands.WebRequestMethod" due to enumeration 
values that are not valid. Specify one of the following enumeration values and try again. The possible enumeration values are "Default,Get,Head,Post,Put,Delete,Trace,Options,Merge,Patch"."
At C:\Users\joshuak\Documents\WindowsPowerShell\Modules\PSTwitterAPI\0.0.7\public\Invoke-TwitterAPI.ps1:34 char:23
+     Invoke-RestMethod @RestMethod_Params
+                       ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (:) [Invoke-RestMethod], ParameterBindingException
    + FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

Looks like the entire image payload is being encoded as part of the URI... which if my understanding of that class is right is capped at 2048 characters? I've tried halving the size of the image, but it's still too long.

I think that shipping this data up as a JSON body on Invoke-RESTMethod would get it up there (I was playing around with this a little, but mucked up the authentication side of things lol)

@Windos
Copy link
Author

Windos commented Mar 4, 2019

Actually, scratch that comment about it being capped at 2048... been playing around and looks like it actually between 64,512 and 65,536 (I was testing in increments of 1024 and really didn't feel like getting more specific than that!)

@mkellerman
Copy link
Owner

Look at how I got the DirectMessages to work with a JSON body:

https://github.com/mkellerman/PSTwitterAPI/blob/master/PSTwitterAPI/public/Send-TwitterDirectMessages_EventsNew.ps1

Care to try your own implementation, and see if that fixes the file size limitation?

@Windos
Copy link
Author

Windos commented Mar 5, 2019

I stumbled upon that and have been playing around, unfortunately still no luck.

Initially I created a new private function ConvertTo-EscapedDataString which escapes the data in chunks, but then of course it finally gets to Invoke-RestMethod and it complains about the length of the final URI.

Then went down the JSON path, and the response back is:

Invoke-RestMethod : {"errors":[{"code":38,"message":"banner parameter is missing."}]}

The documentation for this endpoint and the DM one is subtly different and almost looks like this one won't take JSON.

I've started investigating (after some JS people mentioned it) using 'ContentType' = 'multipart/form-data'... but this is heading in to uncharted territory for me lol.

I'll keep playing.

@Windos
Copy link
Author

Windos commented Mar 5, 2019

Ok... don't think multipart is being accepted. Followed @markekraus example from when support for it was being added to PowerShell core.

Still getting parameter missing response.

@mkellerman
Copy link
Owner

@Windos have you tried with the latest version?

@Windos
Copy link
Author

Windos commented Feb 27, 2020 via email

@mkellerman
Copy link
Owner

I haven't played with sending images.. :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants