You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have the Cloudinary .NET SDK integrated with a Unity project. I've placed the CloudinaryDotNet DLL, as well as all of its DLL dependencies, inside my project. I'm able to access all the Cloudinary namespaces/classes/etc. from my code, which is fantastic.
Unfortunately, when I attempt a simple implementation of Cloudinary.Upload, I get a FormatException. Here's the problem code:
public void UploadImage()
{
ImageUploadParams uploadParams = new ImageUploadParams
{
File = new FileDescription("https://www.fnordware.com/superpng/pnggrad16rgb.png"), // Just a simple gradient image for testing
};
cloudinary.Upload(uploadParams); // FormatException is traced back to this line
}
Before the above method is called in my program, I'm setting my configuration parameters as outlined in the documentation, like this (with my actual info substituted):
Account account = new Account(
"my_cloud_name",
"my_api_key",
"my_api_secret");
Cloudinary cloudinary = new Cloudinary(account);
In case anyone else working inside Unity comes across this same problem, I'll try to detail what I did to fix this here.
The FormatException error was being thrown from the method PrePrepareRequestBody, on line 450 of ApiShared.Internal.cs:
request.Headers.Add("User-Agent", userPlatform);
The issue was the userPlatform parameter. This is created from the static string ApiInternal.USER_AGENT. USER_AGENT is built on line 809 of ApiShared.cs in BuildUserAgent. And this in turn uses System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription to get the name of your .NET installation.
When working inside Unity, FrameworkDescription returns the following string:
Mono 5.11.0 ((HEAD/768f1b247c6)
For some incredibly unhelpful reason, there is a closing parentheses missing from the end of that string, which was making HTTP reject the Header parameter.
I fixed this by adding an additional closing parentheses on the end of the string returned inside ApiInternal.BuildUserAgent. So that method now looks like:
Hopefully this sort of direct meddling with the User-Agent string doesn't negatively impact me in some other way. If anyone has any cautionary advice on this, I'd love to hear your thoughts.
@galenmolk , thank you for reporting this issue!
It is a bit weird bug.
We'll fix it by encoding a header value, so it will be safe regardless of the amount of parenthesis or other unsafe characters.
Hi, hope you're doing well.
I have the Cloudinary .NET SDK integrated with a Unity project. I've placed the CloudinaryDotNet DLL, as well as all of its DLL dependencies, inside my project. I'm able to access all the Cloudinary namespaces/classes/etc. from my code, which is fantastic.
Unfortunately, when I attempt a simple implementation of
Cloudinary.Upload
, I get aFormatException
. Here's the problem code:Before the above method is called in my program, I'm setting my configuration parameters as outlined in the documentation, like this (with my actual info substituted):
Here are the package versions I'm using:
Below is the
FormatException
that I'm getting:I'm working on a Mac inside Unity 2021.1.3f1, which can use either .NET Standard 2.0 or .NET 4.x. Both APIs produce the above error.
Please let me know if there's any additional information I can provide.
Thank you so much. I would really appreciate any insight anyone might have.
All the best,
Galen
The text was updated successfully, but these errors were encountered: