Twitter / X api: binary media upload #7247
Replies: 3 comments
-
|
I could do a working file upload with those changes to "MediaUploadRequestOneShot": public partial class MediaUploadRequestOneShot : IParsable
{
public List<string> AdditionalOwners { get; set; }
public byte[] Media { get; set; }
public MediaCategoryOneShot? MediaCategory { get; set; }
public MediaUploadRequestOneShot_media_type? MediaType { get; set; }
public bool? Shared { get; set; }
public static MediaUploadRequestOneShot CreateFromDiscriminatorValue(IParseNode parseNode)
{
if (ReferenceEquals(parseNode, null)) throw new ArgumentNullException(nameof(parseNode));
return new MediaUploadRequestOneShot();
}
public virtual IDictionary<string, Action<IParseNode>> GetFieldDeserializers()
{
return new Dictionary<string, Action<IParseNode>>
{
{ "additional_owners", n => { AdditionalOwners = n.GetCollectionOfPrimitiveValues<string>()?.AsList(); } },
{ "media", n => { Media = n.GetByteArrayValue(); } },
{ "media_category", n => { MediaCategory = n.GetEnumValue<MediaCategoryOneShot>(); } },
{ "media_type", n => { MediaType = n.GetEnumValue<MediaUploadRequestOneShot_media_type>(); } },
{ "shared", n => { Shared = n.GetBoolValue(); } },
};
}
public virtual void Serialize(ISerializationWriter writer)
{
if (ReferenceEquals(writer, null)) throw new ArgumentNullException(nameof(writer));
writer.WriteCollectionOfPrimitiveValues<string>("additional_owners", AdditionalOwners);
writer.WriteByteArrayValue("media", Media);
writer.WriteEnumValue<MediaCategoryOneShot>("media_category", MediaCategory);
writer.WriteEnumValue<MediaUploadRequestOneShot_media_type>("media_type", MediaType);
writer.WriteBoolValue("shared", Shared);
}I converted the property "media" to Now, the request contains a base64 string and I can confirm that it works. But I don't know whether the X openapi description is correct or not and how Kiota should handle it. So I am far away from creating a feature request issue. Hopefully someone can comment on this problem. |
Beta Was this translation helpful? Give feedback.
-
|
That's interesting: the endpoint upload chunked file follows the same concept, but here Kiota creates a This is the OpenAPI definition: "MediaUploadAppendRequest" : {
"anyOf" : [
{
"type" : "object",
"required" : [
"media",
"segment_index"
],
"properties" : {
"media" : {
"$ref" : "#/components/schemas/MediaPayloadBinary"
},
"segment_index" : {
"$ref" : "#/components/schemas/MediaSegments"
}
}
},
{
"type" : "object",
"required" : [
"media",
"segment_index"
],
"properties" : {
"media" : {
"$ref" : "#/components/schemas/MediaPayloadByte"
},
"segment_index" : {
"$ref" : "#/components/schemas/MediaSegments"
}
}
}
]
},
...
"MediaPayloadBinary" : {
"type" : "string",
"description" : "The file to upload.",
"format" : "binary"
},
"MediaPayloadByte" : {
"type" : "string",
"description" : "The file to upload.",
"format" : "byte"
},Here, Kiota creates byte[] properties (simplified code): public partial class MediaUploadAppendRequest : IComposedTypeWrapper, IParsable
{
public global::XbyOpenApi.Core.Client.Models.MediaUploadAppendRequestMember1 MediaUploadAppendRequestMember1 { get; set; }
public global::XbyOpenApi.Core.Client.Models.MediaUploadAppendRequestMember2 MediaUploadAppendRequestMember2 { get; set; }
}
public partial class MediaUploadAppendRequestMember1 : IAdditionalDataHolder, IParsable
{
public byte[] Media { get; set; }
}
public partial class MediaUploadAppendRequestMember2 : IAdditionalDataHolder, IParsable
{
public byte[] Media { get; set; }
}So, the first OpenAPI definition somehow causes Kiota to create wrong code. I hope that one of the devs reads this, otherwise I will create an issue in the future. |
Beta Was this translation helpful? Give feedback.
-
|
I created #7338 with a stripped down version of the X api spec. Might be a X error or a Kiota problem.... |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
The twitter openapi file ( https://api.twitter.com/2/openapi.json ) defines an endpoint to upload media. It seems the Kiota generated client code does not work.
Description of the endpoint: https://docs.x.com/x-api/media/upload-media
This seems to be the relevant part of the openapi description:
Path:
Components:
Kiota creates classes MediaUploadRequestOneShot, MediaUploadRequestOneShot_media, MediaPayloadBinary and MediaPayloadByte, but the latter two don't have any properties.
Here is a slightly simplified version (for better readability, I removed "#if" declarations and namespaces)
Generating the client prints (among others) those two warnings, which seem to be related:
Is there something missing in Kiota, or are additional steps required to upload the media to X?
Beta Was this translation helpful? Give feedback.
All reactions